Custom API endpoints in Strapi

Strapi's core REST and GraphQL routes cover standard content operations. Custom endpoints add the routers, controllers and services that business logic needs, with output sanitized and the contract documented.

On this page

When custom API endpoints in Strapi are worth building

A custom API endpoint in Strapi is a route, a controller and, optionally, a service that you add to the project to expose behavior the core routes do not cover. Core content routes let a client read and write entries one type at a time. When a front end needs a single call that returns a checkout summary, merges entries from several content types, triggers a workflow or accepts a payload from a partner system, composing core calls becomes slow, chatty or unsafe to expose. That is the point where a team should write a custom endpoint rather than push more logic into the browser or into a series of client requests.

The work lives in your project code: a src/api folder with its routes, controllers and services, all versioned in your repository and deployed with the same pipeline as the rest of the application. Nothing is hosted by DeployOpen or Strapi on your behalf. The endpoint runs in the infrastructure you choose, and it inherits your database, your secrets and your logging. The Community Edition is released under the MIT Expat license, which the Strapi LICENSE file on GitHub documents, but code under the ee directories follows a separate Strapi license. Confirm with Strapi whether any capability you plan to rely on for endpoints, such as an audit trail or a review workflow, sits in the Enterprise Edition before you commit to a design.

Before you build, decide whether the endpoint is needed at all. Ask three questions: does the logic need to run on the server to protect data or credentials, does it touch several content types atomically, and will more than one client call it? If the answer to any is yes, a custom endpoint is usually the right tool. If the need is only a different filter or sort on an existing collection, a query parameter on the core route is cheaper to maintain and easier to upgrade. Write down the owner of each custom route and the consumers that depend on it, because every custom endpoint becomes a contract you must test, document and keep working through each Strapi 5 minor release.

Custom API endpoint options and when each fits

This table compares the five ways to add an endpoint in a Strapi 5 project, from a custom route on a content type to replacing a core controller. Read each row against your own case: the right choice is usually the smallest change that meets the requirement, because every extra layer you own is code you maintain through each Strapi upgrade.

OptionWhen it fitsMaintenance costUpgrade risk on Strapi 5
Custom route on a content typeExtra action on one collection, such as a publish-check or a summary view, that still follows that type's permissionsLow: one route file and a small controller methodLow to moderate: relies on the content type's controller and route names staying stable
Standalone custom routerEndpoint that does not map to one content type, such as a webhook receiver or a cross-type reportLow to moderate: you own the path, auth policy and response shapeLow: independent of core routes, but you must recheck default auth and sanitization after upgrades
Controller wrapping Document Service callsBusiness logic that reads or writes several documents and must return a controlled responseModerate: you own input checks, error mapping and output shapeModerate: Document Service method signatures and response format changes between major versions need review
Service for business logicRules shared by several controllers, jobs or lifecycle hooks, such as pricing or eligibilityModerate: unit tests and a clear contract between service and callersLow: plain TypeScript or JavaScript, so upgrades mostly touch the Strapi calls inside it
Extending or replacing a core controllerCore behavior must change, such as a Users & Permissions registration flowHigh: you carry the core logic and must track its changes in each releaseHigh: core controllers change between minor releases, and overrides can silently drift from the new behavior

Where each piece of logic lives in a Strapi project

The router decides which HTTP method and path reach your code, which handler runs, and which policies and middlewares apply before the handler is called. In a Strapi 5 project, custom routes live in the routes folder of the content API, for example src/api/event/routes/custom-event.ts. Keep routing decisions in this file and nothing else, so anyone reviewing access can read the full list of exposed paths in one place.

  • Method and path: Declare the verb in method, the URL in path, and the controller action in handler, such as event.findUpcoming.
  • Route configuration: Attach policies and middlewares under config so access rules sit next to the route they protect.
  • Public access: Set auth: false only for endpoints that should answer anonymous callers, and record the reason in a comment beside it.
  • Route ordering: Place custom routes so they do not shadow the core routes generated for the same content type, and confirm the match in a test.
  • Keep out: Business rules, database queries and response shaping belong in other layers.

Before release, list every route your project exposes, including those marked auth: false, and confirm the public permissions for each one in the admin panel.

How a custom endpoint request moves through Strapi

The request starts at a client on the public internet and reaches the custom route in the Strapi application. Along the way it passes any route policy or middleware, then the controller, which hands business logic to a service. The service reads and writes through the Document Service API or the database, and the response goes back through sanitizing before it leaves. Check each hand-off where a trust boundary is crossed, and confirm that the sanitizing step covers every field the service returns, including relations pulled in by populate.

Request path from a client through the Strapi application to the database and an external system.

Setting up a custom API endpoint in Strapi

This sequence takes a custom endpoint from a written contract to a tested, documented route that returns only the fields the consumer is allowed to see. Each step ends with a check the team can run locally before the endpoint reaches a shared environment.

  1. Confirm runtime versions and database target

    The team confirms the Node.js version and database the project will run on before writing any code. Strapi 5 runs only on Active or Maintenance LTS Node.js versions and supports PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later and SQLite 3, and does not support MongoDB or other NoSQL databases. Confirm these against the current installation requirements page and against the versions your hosting environment provides. The step is done when the team can run the project locally on the same Node.js and database versions planned for staging, and the project starts without errors.

  2. Define the endpoint contract

    Write down the endpoint before the code: the HTTP method and path, the authentication required, the request parameters and body fields with their types, the response shape, and the error cases such as a missing record or a forbidden role. Name the content types it reads or writes and list which fields must never leave the server. Consumers and the security reviewer should sign off on this document. The check is a short contract file or ticket that a second engineer can read and reproduce a sample request and response from without asking questions.

  3. Create the router and controller

    Add a route definition under the API folder for the content type or a custom path, set the method and path, and point it at a controller action. The controller reads the validated input from the request, calls a service for any business logic, and returns the result. Keep the controller thin so the rules live in one place. Check by starting Strapi, confirming the route appears in the route list, and sending one request with a valid token and one with no token. The authenticated call should return a 200 response with the expected shape, and the unauthenticated call should be refused once access is set in the next step.

  4. Move business logic into a service

    Create a service file that holds the rules the endpoint enforces, such as calculating totals, checking state transitions or looking up related records. The service reads and writes content through the Document Service API rather than the older Entity Service API. Controllers call the service and do not query the database directly. The check is a unit or integration call to the service function from a small test script, with expected inputs producing the expected output and invalid inputs throwing a clear error.

  5. Set route-level access

    Decide who may call the endpoint and enforce it on the route, using the Users & Permissions role for end users or an API token scope for machine clients. Add policies for ownership or business rules where the role alone is not enough. Confirm that public permissions do not grant the new route unless the contract says so. Check with three requests: one with no token, one with a token that lacks the permission, and one with a permitted token. The first two should be refused and the third should succeed. Record the results so the security reviewer can repeat them.

  6. Sanitize the response

    Shape the output so only the fields in the contract leave the server. Strip private fields, unpublished drafts, relations that were populated by accident and any fields that depend on the requester's role. Confirm how your Strapi version applies default sanitization to responses and do not assume the default covers custom payloads. The check is a request that populates related content and inspects the JSON, confirming that no password hashes, internal IDs, tokens or draft-only fields appear. Repeat the check with an authenticated user of each role that can call the endpoint.

  7. Add automated tests

    Write tests that cover the happy path, the unauthenticated and unauthorized cases, invalid input and the sanitized output fields. Run them against an in-memory SQLite instance or the same database engine used in staging, depending on your test setup. Confirm the test command runs in continuous integration before merge. The check is a green run locally and in the pipeline, and a deliberate break, such as removing a policy, that makes the suite fail. Ask your team which test framework and database they will standardize on before writing the first test.

  8. Document the endpoint and hand it over

    Publish the contract, the request and response examples, the required token or role, the error codes and the known limits in the repository or your API documentation tool. If the endpoint is part of a public or partner API, list it in the documentation index and note the Strapi version it was built on so the upgrade team can find it. The step is complete when a consumer can make a successful call using only the documentation and a test token, and when the team has confirmed in its own environment that the staging deployment matches the tested build.

Sanitizing output so custom endpoints do not leak data

A custom controller can return fields that the core content API would never expose, because the core routes apply output filtering that a hand-written controller does not get for free. When you return the result of a Document Service call directly, every attribute on the entry comes with it, including private or internal fields, and any relation pulled in by a populate argument arrives with its own attributes. Editors may have designed those relations for the admin panel, not for the public. The first check is to list, for each custom endpoint, every field and relation the response can contain, and to compare that list with what the matching core route returns to the same role.

The sanitizing approach is to decide the output shape explicitly before the response leaves the controller. Build the response from an allowlist of fields and relations for each consumer, and strip anything else, including nested objects produced by populate and any attribute marked private in the content type schema. Keep the shape stable: the same keys, the same nesting and the same types across releases, so front-end and integration code does not break when the internal model changes. Confirm with your Strapi version how the core sanitizer and the private attribute option behave, and decide whether you will reuse them or write a small mapping function in the service layer. Either way, document the shape alongside the endpoint so reviewers can check it.

Test the endpoint with roles that should see less, not only with an administrator token. Create a public or unauthenticated request, an authenticated end user with a restricted role, and an editor whose permissions cover only part of the content. For each, compare the raw response with the expected allowlist and look for leaked relations, draft or unpublished content, internal IDs and fields that a related content type restricts. Add these cases to your automated test suite so that a later change to a populate argument or a schema attribute fails the build. Ask your security reviewer to sign off on the list of fields per role before go-live, because the reviewer, not the developer, should decide what counts as internal.

Security checks for custom API endpoints in Strapi

A custom endpoint adds a new attack surface next to the routes Strapi generates for you. The cards below cover the mistakes we see most often in custom routes, controllers and services, with the control to put in place and the test that proves it works. Run these checks before every release that changes a route.

Unintended public permissions

A new route in src/api/*/routes inherits whatever the Users & Permissions role grants, and the Public role is the usual cause of exposure. Set auth explicitly on each route, and grant Public access only to endpoints that are meant to be open. The test is a request with no token against every new route, expecting a 401 or 403 unless the route is on the approved public list.

Strapi SSO docs

Missing ownership checks in services

A service that loads a record by ID without checking the caller's ownership lets any authenticated user read or change someone else's data. Pass the authenticated user into the service and filter queries by owner, or check ownership before any write. The test is a two-user case: user A requests user B's document ID and must receive a not-found or forbidden response, with no change to the record.

Unvalidated input in queries and calls

Request values that flow into filters, sort clauses, URLs or outbound HTTP calls can change query behavior or reach internal hosts. Validate types and allowed values in the controller, reject unknown keys, and build outbound URLs only from an allowlist. The test sends malformed, oversized and injection-style payloads to each parameter and checks that the response is a validation error and that no unexpected query or request is made.

Verbose errors that expose internals

Returning raw exception messages, SQL fragments, stack traces or internal IDs helps an attacker map the system. Throw Strapi's errors with a short, fixed message, and log the detail server-side only. Check that the production configuration disables stack traces, then trigger a database error and a downstream timeout and confirm that the response contains only the generic message.

Secrets stored in controller code

API keys for payment, email or AI providers written into controllers or services end up in source control, build artifacts and logs. Read them from environment variables through the Strapi config, and scope each key to the single purpose it serves. Verify with a secret scan of the repository and build output, and confirm that the endpoint works after the key is rotated in the environment alone.

Logging of sensitive payloads

Logging whole request bodies, tokens, personal data or provider responses turns logs into a data store that often has weaker access controls. Log an event name, the user or document ID and the outcome, and redact fields such as passwords, tokens and personal identifiers. The test submits a request carrying a known marker value in sensitive fields and searches the application logs for that value.

How much does a custom API endpoint in Strapi cost to build

What drives the cost of a custom API endpoint in Strapi?

The cost follows the number of endpoints, how much business logic sits behind each one, and how many external systems it must touch. Each endpoint needs a route, a controller, a service for its rules, output sanitizing and documentation, so the count multiplies the work. Access model matters too: public routes, role-based routes and ownership checks each add design and test effort. Integrations with payment, CRM or identity systems usually cost more than the Strapi code itself because they depend on systems you do not fully control. Testing and documentation are often underestimated and should be priced as separate line items.

Can a small in-house team build custom Strapi endpoints themselves?

A team with working knowledge of Node.js and Strapi's server structure can build simple endpoints in-house, especially read-only routes over existing content types. The harder parts are sanitizing responses so that populated relations do not leak data, enforcing policies consistently, and keeping custom code working through Strapi upgrades. If your team has no one who has written Strapi controllers and services before, plan for a learning period and a review by someone experienced. Ask whether the internal owner will also maintain the code after launch, since that ongoing cost is often what decides the question.

How long does it take to build a custom Strapi endpoint?

Duration depends on scope rather than on a standard figure, so no fixed timeline applies. A single endpoint over an existing content type with simple rules is a small piece of work, while a set of endpoints that combine transactions, third-party calls and role-specific output can take considerably longer. The main schedule risks are unclear business rules, late access decisions and waiting for test environments or sample data. Ask for a timeline tied to a written list of endpoints, their rules and the systems they touch, and check which milestones depend on your input.

What does our team need to provide before endpoint work starts?

Start with the data model: the content types, components and relations the endpoints will read or write, including which fields are private. Provide written access rules that state who may call each endpoint and under what conditions, plus sample request and response payloads from the consumer. A test environment with a Strapi instance and a seeded database, and a copy of any external API credentials or sandbox accounts, are also needed. Without these inputs, the work tends to stop while assumptions are checked, which extends the schedule and adds cost.

What recurring work follows a custom Strapi endpoint after launch?

Custom endpoints need ongoing attention because they depend on Strapi's internal APIs, which change between major versions, and on Node.js and npm packages that receive security updates. Plan for regular dependency updates, re-running the test suite after each Strapi upgrade, and reviewing access rules when roles or content models change. Monitoring errors and slow responses on custom routes is also recurring work. Costs for these tasks repeat for as long as the endpoints remain in service, so include them in the total cost of ownership rather than treating the build as a one-time expense.

How much do Strapi plans cost, and does the plan change the endpoint cost?

For self-hosted Strapi, the Community edition is free and has unlimited users, while the Growth plan is listed at 45 US dollars per month including 3 users, plus 15 dollars per extra user, according to Strapi's self-hosted pricing page. Enterprise pricing is custom. All listed self-hosted plans include REST and GraphQL APIs, so custom REST endpoints do not on their own require a higher plan. Features such as SSO, audit logs and content history do differ by plan, so confirm your access and audit needs before you choose a tier. Check the current figures on the pricing page, since plan details change.

What should a written quote for a custom Strapi endpoint include?

A useful quote lists every endpoint with its method, path, input and output, and states which business rules and access checks apply to each. It should name the integrations included, the testing approach (such as automated API tests and manual checks), and the documentation delivered. Ask for the assumptions behind the estimate, the client inputs required and the acceptance criteria for each endpoint. Also ask which items are one-time and which recur, such as upgrade support or dependency updates, and how changes to scope after the quote are priced. DeployOpen works from a written scope, so the quote follows from that document.

Limits to confirm before you commit to a custom endpoint design

A custom endpoint depends on the Strapi version, the runtime and database beneath it, the plan you pay for, and the behavior of APIs that may change. Each card below names one limit to verify in your environment and the person who should confirm it, before the design is locked and the code is written.

Strapi version and endpoint pattern

Confirm which Strapi 5 minor release your project runs and whether the router, controller and service pattern you plan to use is documented for that version. Strapi ships minor releases often, so pin one version and record it in the design. Ask your platform lead to check the release notes against your planned code, and ask your Strapi partner to test the endpoint on that exact version before it reaches staging.

Strapi releases

Node.js and database support

Strapi 5 runs only on Active or Maintenance LTS Node.js versions, and it supports a fixed list of databases. Confirm with your infrastructure team that the Node.js runtime in your build and hosting images is on that list, and that your production database version is supported. Custom queries that rely on database-specific SQL may behave differently across the supported engines, so test them on the database you run.

Installation requirements

Features covered by your plan

Some features an endpoint depends on, such as audit logs, review workflows, and content history, are limited to specific self-hosted plans. Confirm with your Strapi account contact and your procurement team which plan you hold and whether the endpoint needs any feature outside it. Also confirm that licensing terms apply to any code you place under enterprise directories.

Self-hosted pricing

Transactions and experimental APIs

Endpoints that write several records at once may need database transactions, and the transaction API is marked experimental in the Strapi docs. Confirm with your Strapi developers whether the API you plan to use is stable on your version, and decide how your team will handle failures and rollbacks if the API changes. Record that decision in the design so reviewers can see the risk.

Custom code during Strapi 5 upgrades

Custom routes, controllers and services can break when Strapi changes its Document Service API, response format or plugin behavior in a future upgrade. Ask your upgrade owner to list every custom endpoint, its dependencies and its tests, and to run those tests against a staging copy before any production upgrade. Confirm the back-up and rollback steps with the same owner, because downgrading is not supported.

Migration FAQ

Performance of calls that bypass caching

An endpoint that skips the default pagination, populate limits or caching of core routes can return large payloads or run heavy queries under load. Ask your performance engineer to set a response size limit and a query budget for each endpoint, and to load test it with realistic data volumes on your database. Confirm with your security team that the endpoint does not expose more fields or records than the sanitized output allows.

Documenting custom endpoints so consumers can rely on them

A custom endpoint is only usable by front-end and integration teams if its contract is written down and kept accurate. For each route, the contract should state the HTTP method, the full path including the /api prefix, every path and query parameter with its type and whether it is required, the authentication requirement (public, an API token with a named scope, or a logged-in end user from the Users & Permissions plugin), the response shape with an example body, the error codes the endpoint returns and when, and the versioning expectation, such as whether a path change is a new route or a breaking change to an existing one. Include at least one example request and response for the success case and one for a common failure. Write the contract from the controller and the route file, not from memory, and confirm the exact response envelope your Strapi version produces, since Strapi 5 changed the default response format.

Keep the contract in the repository beside the route, controller and service it describes. A practical pattern is a docs folder in the Strapi project or an OpenAPI file that is reviewed in the same pull request as changes to src/api/<name>/routes and the controller. Any change to a route's policies, middlewares or sanitized output should require a matching contract change in review. Share the rendered documentation with front-end and integration teams through a location they already use, and tell them which version of the Strapi project it reflects. Ask your team to confirm whether the Strapi admin or the Documentation plugin is used for other APIs, so that custom endpoints are not documented in a second, conflicting place.

Drift is most likely during a Strapi upgrade, when response formats, sanitization defaults and permission handling can change. Before an upgrade, record a set of representative requests and their responses for each custom endpoint, run the same requests against a staging copy after the upgrade, and compare status codes, field names, nesting and authentication results. Automated contract tests, for example with Jest and Supertest as covered in the testing section, can fail the build when a documented field disappears. Review the Strapi release notes for the version you are moving to, and confirm each item that touches your endpoints before you rely on the comparison.

How DeployOpen scopes and delivers custom Strapi endpoints

DeployOpen plans, builds, tests and documents custom API endpoints inside your own Strapi project and infrastructure. Each engagement starts with a written scope that names the routes, business rules and response shapes involved, so your team knows what will be delivered before any code is written.

How we scope

  • Inventory the endpoints that core routes cannot serve and the business rules each one must enforce.
  • Define request and response contracts, including which content fields and relations may leave the API.
  • Record the Strapi version, database and Node.js runtime the endpoints must support before work starts.
  • Agree the written scope, deliverables and timeline with your team; engagements are fixed-scope.

How we build

  • Create custom routers and controllers in the project, with services holding the business logic.
  • Apply input validation, authorization policies and output sanitizing to every new route.
  • Write automated tests for success paths, permission failures and malformed requests.
  • Review query and populate behavior so endpoints do not expose fields that editors or users should not see.

How we hand over

  • Deliver the endpoint code in your repository with a documented route list and permission matrix.
  • Document the request and response examples, error formats and any required roles or tokens.
  • Walk your developers through the code, the tests and how to add the next endpoint safely.
  • Confirm with your own environment the documentation format and tooling your team uses.

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer for endpoints in production.
  • Retest endpoints after Strapi minor releases and before planned Strapi 5 upgrades.
  • Keep changes scoped to the endpoints agreed, with any further work priced from a new written scope.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.