When the Strapi Client library is the right choice for your JavaScript app
Use @strapi/client when your Next.js, Astro, Vite or Node front end talks to Strapi 5 over the REST API and you want the collection, single type and file calls, token authentication and documentId handling built in rather than maintained in your own code. Use hand-written fetch calls when the app needs only one or two read requests, when the front end runs in an environment where you want no extra dependency, or when your team already has a typed fetch wrapper that covers every endpoint it uses. The choice is about maintenance cost, not about whether Strapi works either way. Every project will still need to decide how it attaches the API token, which environment variables hold the Strapi URL, and which fields it requests from each endpoint.
The library covers four areas that teams otherwise rebuild by hand. It gives you collection methods for content types that return lists, single type methods for content that exists once per site, file methods for uploads, and a token setup for requests that need authentication. It also works with documentId, the identifier Strapi 5 uses to address a document across its draft and published versions, so your code does not have to mix numeric IDs with document identifiers. Confirm the exact method names, option shapes and supported client configuration against the version of @strapi/client you install, and check them against the Strapi documentation for your Strapi 5 release before you build wrappers around them.
Before you commit, check three things in your own project: whether the API tokens your front end uses have only the read permissions it needs, whether any build or server environment will call Strapi from code that must stay free of extra packages, and whether your team's existing data layer already handles pagination, errors and draft requests consistently. If the answers point to a single reader with a small set of endpoints, raw fetch is often enough. If several teams call many content types and need consistent behavior, the library gives you one tested surface to review and upgrade. Record the decision in your architecture notes so that a later Strapi 5 upgrade includes a check of the client version.
Which client approach fits which app
This table compares @strapi/client, a small typed fetch wrapper and the Nuxt or Astro integrations across token location, uploads, runtime and code ownership. Read each row against your app's runtime, and use the final row to decide what to confirm before you commit.
| Decision factor | @strapi/client | Hand-written typed fetch wrapper | Nuxt or Astro integration |
|---|---|---|---|
| Where the API token lives | Server side only, if the client is created in server code and the token stays out of browser bundles | Wherever your wrapper runs, so you control whether it executes on the server or in the browser | Framework server routes or server-side composables, with the module's configuration defining the URL and token |
| Browser use | Possible, but a read-only public token is the only safe choice in browser code | Possible, with the same token exposure risk as any client-side secret | Usually server-rendered data, with client-side calls depending on the module's options |
| File upload needs | Includes file methods, so check the upload path against your media and permission settings | You write multipart requests and error handling yourself | Depends on the module and the upload path your app uses |
| Typed responses | Confirm how typed the methods are for your content types in your installed version | You define the types and keep them in sync with your schema | Depends on the framework's type generation and module version |
| Code your team owns | Small: you maintain configuration and calls, the library maintains request handling | Largest: retries, errors, pagination and types are your code | Moderate: you follow the module's conventions and upgrade it with the framework |
| Best fit | Plain JavaScript or TypeScript apps that call Strapi from server code or a trusted backend | Apps with unusual request needs or a strict rule against adding a dependency | Nuxt or Astro sites that want framework-native fetching and preview support |
| What to confirm first | The package version compatible with your Strapi 5 instance and its documented methods | Which request behaviors your team must own, such as retries and documentId handling | The module version for your framework and whether preview and token handling match your security review |
How documentId changes the way you address entries
In Strapi 5, each entry has a documentId that stays the same across its draft and published versions, and it is the identifier your client calls should use for most single-entry operations. The numeric id still exists, but it points to one stored row, so a draft and its published version can have different numeric IDs while sharing one documentId. When you call client.collection('articles').findOne(documentId) or update and delete an entry through the client, pass the documentId value from the response. Treat the numeric id as an internal detail unless a specific endpoint or your own data model still depends on it.
This matters for three things in your JavaScript app. Route parameters such as /articles/:documentId remain valid after an editor publishes a new version, so your URLs do not need to change when content moves between draft and published states. Caches keyed by documentId can be invalidated per document rather than per row, which keeps purge logic simpler. Relations you store on the front end should reference documentId, because a numeric id taken from a draft response may not match the published copy your site reads. Confirm the exact behavior of the client's status and locale parameters against the Strapi documentation for your installed version before you write this logic.
Before you build, check how your front end stores identifiers today. Search your code for id fields in route definitions, state stores, cache keys and foreign keys saved from Strapi responses, and decide which ones should become documentId. Existing projects migrated from Strapi 4 may still pass numeric IDs. The Document Service API is the server-side layer that handles these documents, and the Strapi-Response-Format: v4 header can make responses look like the older format during a migration. Treat that header as a temporary aid, not a design target, because it does not change how new code should address entries. Plan to remove it once your client code and data lookups use documentId throughout, and test that migration path in a staging copy of your project.
How to set up @strapi/client with an API token
This sequence takes a JavaScript project from no Strapi access to a first successful collection read using a narrowly scoped, read-only API token kept on the server. Each step ends with a check so the team knows the setup works before any front-end code depends on it.
Confirm the Strapi base URL and version
A developer confirms the Strapi instance the app will read from, including its base URL for the environment (development, staging or production) and that the instance is Strapi 5. Read the Strapi installation requirements to confirm the runtime is supported before going further. Done when the team can open the admin panel and the REST endpoint for a public content type in a browser and get a response.
Install the client package
In the front-end or server project, the developer adds @strapi/client using the team's existing package manager, such as npm, pnpm or yarn, and commits the updated lockfile. Keep the install in the server-side part of the codebase where the token will live. Done when the package appears in the dependency list and the project builds without errors.
Create a read-only API token
An administrator opens the Strapi admin panel, creates a read-only API token in the settings, and sets the shortest lifetime and narrowest scope the content requires. Grant find and findOne only on the content types the app displays, and leave create, update and delete unchecked. Done when the token is shown once and the admin has copied it to the team's secrets store.
Store the token as an environment variable
The developer saves the token and the base URL as server-side environment variables, such as STRAPI_URL and STRAPI_API_TOKEN, in a local .env file that is excluded from version control and in the hosting platform's secret settings for other environments. Confirm that the variable names match what the code reads. Done when a test script prints the variable's length, not its value, and the file is listed in .gitignore.
Initialize the client with the base URL and token
In a server-side module, the developer creates the client with the Strapi base URL and the API token read from the environment, and exports it for use by route handlers or data loaders. Avoid placing the token in any file that a bundler processes for the browser. Done when the module imports cleanly and the client object is created without throwing an error.
Make a first collection call
The developer calls the client's collection method for a public content type, such as articles, and requests only the fields the page needs. Log the response in a server process, not the browser. Done when the call returns the expected entries and the response contains only fields the token's scope allows.
Verify token scope and browser exposure
The team checks that a write request with the token fails with a permission error, that a content type outside the token's scope is not returned, and that a production build of the front end contains no occurrence of the token value. Search the built JavaScript files for the token string and the variable name. Done when all three checks pass and the results are recorded in the project's setup notes.
Collection, single type and file methods side by side
Collection types hold many entries, such as articles, products or locations. Collection methods cover list reads, single-entry reads and writes. In illustrative code, a list call might look like client.collection('articles').find() and a create call like client.collection('articles').create({ title: 'Draft' }), but confirm the exact method names and argument shapes against the client version you install.
- List and filter: list calls accept options for filters, field selection, populate and pagination, so define what the frontend needs before writing the call.
- Single-entry reads: reads and updates address an entry by its
documentId, the identifier Strapi 5 uses in its responses. - Write methods: create, update and delete need matching permissions on the content type for the role or token in use, separate from read access.
- Draft and published versions: confirm whether a call returns the draft or the published version and how the status is requested.
- Error handling: treat a 403 caused by missing permissions differently from a 404 for an unknown document.
Check that every method your application calls is granted on the role or token you issue, and test writes on a non-production instance first.
Single types hold one entry per content type, such as a homepage, site settings or a footer. Client calls read and write that one document without a collection-style identifier in the path. In illustrative code, a read might look like client.single('homepage').find() and an update like client.single('homepage').update({ heroTitle: 'Welcome' }), with names confirmed against your installed client.
- Layout reads: a homepage or navigation fetch is usually a single call, so populate only the components the page renders.
- Update-style writes: most edits update the one document, so confirm whether create and delete apply to your single types in your version.
- Draft and publish states: single types have their own draft and published states, so confirm which one the frontend should read before launch.
- Separate permissions: the find permission used for public reads is distinct from the update permission that editors or automated jobs need.
- Cache and rebuild timing: a single type changes rarely, so agree cache lifetimes with editors and tie rebuilds to update events.
Confirm which single types are public, which tokens can write to them, and who approves changes in production.
File methods upload media through the Upload plugin and return file records that content entries reference. A typical flow uploads the file first, then attaches the returned record to a media field on an entry. In illustrative code, this might look like client.files.upload(formData) followed by client.collection('articles').update(documentId, { cover: fileId }), with the exact names confirmed against your installed client.
- Upload permission: uploading needs the upload permission for the token or role, which editors often need separately from entry creation.
- Two-step attach: store the identifier returned by the upload on the entry's media field, not the raw file name or URL.
- Browser versus server: keep write-capable tokens on the server, since a token exposed in browser code can be used to upload anything it is permitted to.
- File types and size limits: confirm allowed MIME types and size limits in the upload configuration before building a client that accepts user files.
- Orphaned files: uploads that never attach to an entry stay in the media library, so agree a cleanup routine with the editorial team.
Verify that upload, attach and delete all work with the exact token type that your production frontend and back-end jobs will use.
Security and operational risks in client-side token handling
Client code that talks to Strapi is where tokens, permissions and error handling meet. The risks below connect because a leak in one place, such as a full-access token in browser code, turns a small configuration gap into full read or write access to content.
Full-access tokens in browser code
A full-access API token placed in a browser bundle is readable by anyone who opens the page source or network tools, and it grants whatever that token was created to do. Use a read-only token scoped to the content types the front end needs, and keep any write token on a server you control. Before launch, search the built output for the token value and confirm the bundle contains only public configuration.
Overbroad public permissions
Public role permissions apply to every visitor who calls the API without a token, so a permission granted for a preview page can expose draft-adjacent fields or whole collections. Review the Public role for each content type and field, and confirm that create, update and delete actions are disabled. The Strapi security configuration topic covers the full permission review.
Draft and published content handling
In Strapi 5, the Client reads published entries by default, and requests that target drafts need a token and an explicit status choice. If the code does not handle a missing entry or an unauthorized response, editors may see blank pages, and a draft-capable token used in public code can leak unpublished copy. Test each page with a published entry, an unpublished entry and a revoked token.
Strapi SSO docsToken rotation and revocation
Tokens in a deployed client keep working until someone removes them, so a token shared with a contractor or copied into a repository stays live. Plan a rotation step that creates the new token, updates the environment variable, deploys, and then revokes the old token. Record the owner and purpose of each token so that a rotation can be scheduled without guessing which applications depend on it.
Request URL logging
Some tooling logs full request URLs, and a token passed as a query parameter or a populated preview link can end up in proxy logs, error trackers and browser history. Keep tokens in Authorization headers, mask them in application logs, and review what your reverse proxy and monitoring tools record. Confirm log retention and access before you enable verbose request logging in production.
CORS settings on the Strapi side
CORS controls which browser origins can call the Strapi API, and a wildcard or an overly long origin list lets other sites make requests from a visitor's browser. Allow only the production and staging front-end origins, and confirm that the list matches the environment variables used by the client. Check the setting after every deployment, because a copied configuration file can carry over a development origin.
Questions teams ask before using the Strapi Client library
Does the Strapi Client library replace fetch entirely in a JavaScript app?
No. The client wraps calls to Strapi's REST API, so it covers the requests your app makes to Strapi, while other services can keep using fetch or their own SDKs. Most teams still use plain HTTP for webhooks, third-party APIs and any custom Strapi route the client does not expose, so the code base usually keeps some fetch calls. Check each endpoint your app depends on against the client's method list before you commit, including custom routes you added in your own Strapi project. The main reason to adopt it is consistency: one place handles base URL, headers, authentication and response handling, which reduces duplicated fetch wrappers across pages and components. Confirm the supported Strapi version range in the client documentation, because your instance's version decides which response format your code receives.
What does it cost to adopt the Strapi Client library?
The package cost is rarely the main line item, because adoption is mostly engineering time. Cost rises with the number of fetch call sites to convert, the number of environments and tokens you manage, how much authentication logic changes, and how many automated tests you add to protect the work. A small read-only site with a handful of calls is a small change, while a large application with file uploads, preview modes and per-user requests takes more review. The recurring cost is ownership: someone must track client releases, Strapi upgrades and any response-shape changes, then update the code when they land. When you request a quote, ask for the number of call sites in scope, the environments covered, the test approach and who handles upgrades after go-live. Confirm the client's license terms in its repository before you adopt it.
How long does a basic Strapi client integration take to build and review?
No duration has been set for this work, so treat any timeline as something to confirm in writing. Build time depends on how many screens or routes read Strapi content, how complex the populate queries are, whether editors need draft or preview content, and how many environments must match. Review time depends on how many people must sign off: the frontend lead checks data shapes, the security owner checks token scope, and the content team checks that editors see the expected results after publishing. Ask for a written plan that lists the endpoints in scope, the milestones, the test cases and the review steps, with the dates each one depends on. A scope that names the content types and routes up front makes both the build and the review easier to estimate.
What must our team provide before a Strapi client integration starts?
Four inputs decide whether the work starts smoothly: a running Strapi instance, a token policy, a content model and a named decision owner. The instance should be reachable from where the frontend runs, on a Strapi version your team has confirmed, with a staging copy for testing. The token policy should state which API tokens the app uses, whether they are read-only, how they are stored and how often they rotate. The content model should list the content types, relations, components and fields the app will read, along with the document identifiers your code will use. Name a person who can approve permission changes and resolve questions about editorial behavior. Missing any of these usually adds rework later, so record them in the statement of work as client inputs with due dates.
Can one in-house developer build a Strapi client integration alone?
Yes, for a small, read-only integration that one developer already understands, provided that person has time to read the Strapi documentation and test against real content. The work gets harder when the app needs authenticated requests, file uploads, draft content, multiple environments or a frontend framework the developer has not used. A single person also becomes a single point of failure for reviews, so a second engineer should check token handling and error paths before launch. Ask whether your team has someone who understands the Strapi 5 response format, can write tests for populated relations and will own upgrades later. If the answer is unclear, a partner can handle the build while your developer learns the code, which keeps knowledge inside your team. DeployOpen implements and documents these integrations in infrastructure you control, with scope agreed in writing before work starts.
How does migrating from Strapi v4 response shapes affect the client?
Code written for v4 expects the older response shape, so it must change when the instance moves to Strapi 5, and the client should be written against the response format of the version you run. Strapi 5 replaces the Entity Service API with the Document Service API and changes the response format, and it offers a Strapi-Response-Format: v4 header during migration. Treat that header as a temporary bridge only. Plan the change endpoint by endpoint: list every read, update the parsing code and test each populated relation and media field against the new shape. Strapi v4 reached end of life on April 30, 2026, so teams still on v4 should treat the migration as a dated risk. Read the Strapi v4 to v5 migration introduction and FAQ and back up the database first, because downgrading is not supported.
Which Strapi client behaviors should we test before go-live?
Test the behaviors your users see, plus the failures your app must survive. Confirm that each collection and single type call returns the fields and relations your pages need, with populate settings that match each view. Check that file methods return media URLs your frontend can display, including in preview and in any environment that serves media from a separate host. Verify documentId handling on updates and deletes, and confirm your code references entries by their document identifier. Test token scope by calling protected endpoints with a read-only token and expecting write attempts to fail. Finally, test error handling for missing entries, expired tokens and an unreachable instance, and confirm the app shows a sensible state for each. Ask your team or your partner to record these checks as a repeatable test suite so the same checks run after each client or Strapi upgrade.
A browser request never holds the Strapi API token
The diagram starts in the browser or a server component, where environment variables supply the Strapi URL and, on the server only, the API token. @strapi/client builds the request and sends it to the Strapi REST API, which checks the token and the role's permissions before it queries the database. The point to check is the dashed boundary: any token that appears in browser-delivered code is visible to every visitor, so public reads should use a public role and privileged calls should stay on the server.
Where the API token lives and how a request reaches Strapi.
How DeployOpen scopes and delivers a Strapi client integration
DeployOpen treats a move from hand-written fetch calls to @strapi/client as a scoped engagement: we map the endpoints, token handling and documentId usage your front end needs before any code changes. The work is delivered in your own repositories and hosting, with the setup documented so your team can maintain it after handover.
How we scope
- We inventory the current fetch calls, content types and endpoints your front end uses today.
- We agree in writing which collection, single type and file methods the integration will cover.
- We confirm the Strapi version, Node.js runtime and hosting targets before design starts.
How we build
- We configure the client once, with the base URL and API token read from environment variables.
- We replace fetch calls in agreed modules, keeping documentId references consistent across pages.
- We test read, write and file upload paths against a staging Strapi instance before release.
How we hand over
- We deliver the client configuration, token scope notes and a short runbook for your developers.
- We document which endpoints use public permissions and which use authenticated API tokens.
- We walk your team through the test suite and the steps for adding a new content type.
How we support
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing first.
- Ongoing support, Strapi upgrades and continuous testing are available as a retainer.
- Retainer scope, such as updates after Strapi minor releases, is agreed in the written quote.

