API reference
createEndpoint
Build a single endpoint without a service or an API object.
const endpoint = createEndpoint(config, fetcher?);
Use this for a one-off endpoint. Inside a createApi tree you never call it — createApi does, after cascading configuration down.
Config
endpointstringRequired
- Name of the endpoint. Appears in cache keys and error messages.
method'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'Required
- Gates capabilities at compile time: a non-GET endpoint has
useQuerytypednever. - GET and DELETE send parameters as a query string; the rest send a JSON body.
pathstringRequired
- Relative to the origin.
:nameis a required segment,:name?an optional one. - Never put the origin here — that is
baseUrl.
servicestringdefaults to ''
- Leading segment of the cache key. Set for you by
createApi.
baseUrlstring
- Origin for this endpoint. Passed to the fetcher on every call.
requestSchemaAnyValidator<TReq>
- Validates the request body or query parameters, and gives the request its type.
- Must be synchronous.
responseSchemaAnyValidator<TResp> | { schema, mode: 'async' }
- Validates the response and gives the result its type.
- Declare
mode: 'async'to resolve data immediately and validate in a detached promise.
pathParamsSchemaAnyValidator<TPath>
- Validates bound path parameters before the URL is built, and types
withPathParams. - A failure raises a
path-validationerror and reachesonRequestValidationErrorwithsource: 'path'.
getNextPageParam(lastPage, allPages) => Partial<TReq> | null | undefined
- Declaring this unlocks
useInfiniteQueryand the suspense variant. - Return
nullorundefinedwhen there are no more pages.
maxPagesnumber
- Caps how many pages are retained, passed to TanStack unchanged.