Skip to main content

API reference

Config options

The optional config options allow you to customize Next REST Framework. The following options can be passed to the defineDocsRoute (App Router) and defineDocsApiRoute (Pages Router) docs route handler functions:

NameDescription
deniedPathsArray of paths that are denied by Next REST Framework and not included in the OpenAPI spec. Supports wildcards using asterisk * and double asterisk ** for recursive matching. Example: ['/api/disallowed-path', '/api/disallowed-path-2/*', '/api/disallowed-path-3/**'] Defaults to no paths being disallowed.
allowedPathsArray of paths that are allowed by Next REST Framework and included in the OpenAPI spec. Supports wildcards using asterisk * and double asterisk ** for recursive matching. Example: ['/api/allowed-path', '/api/allowed-path-2/*', '/api/allowed-path-3/**'] Defaults to all paths being allowed.
openApiSpecOverridesOverrides to the generated OpenAPI spec.
openApiJsonPathPath that will be used for fetching the OpenAPI spec - defaults to /openapi.json. This path also determines the path where this file will be generated inside the public folder.
autoGenerateOpenApiSpecSetting this to false will not automatically update the generated OpenAPI spec when calling the Next REST Framework endpoint. Defaults to true.
docsConfigA Docs config object for customizing the generated docs.
suppressInfoSetting this to true will suppress all informational logs from Next REST Framework. Defaults to false.
generatePathsTimeoutTimeout in milliseconds for generating the OpenAPI spec. Defaults to 5000. For large applications you might have to increase this.

Route config

The route config parameters passed to the defineRoute (App Router) and defineApiRoute (Pages Router) functions define an individual route, applicable for all endpoints that are using that route:

NameDescriptionRequired
GET \| PUT \| POST \| DELETE \| OPTIONS \| HEAD \| PATCHA Method handler object.true
openApiSpecOverridesAn OpenAPI Path Item Object that can be used to override and extend the auto-generated and higher level specifications.false

Method handlers

The method handler parameters define an individual endpoint:

NameDescriptionRequired
inputAn Input object object.false
outputAn array of Output objects. true
handlerA strongly-typed handler function for your API. The function takes in strongly-typed versions of the same parameters as the Next.js Route Handlers and API Routes handlers.true
openApiSpecOverridesAn OpenAPI Operation object that can be used to override and extend the auto-generated and higher level specifications.false
Input object

The input object is used for the validation and OpenAPI documentation of the incoming request:

NameDescriptionRequired
contentTypeThe content type header of the request. A request with no content type header or a incorrect content type header will get an error response.true
bodyA Zod schema describing the format of the request body.true
queryA Zod schema describing the format of the query parameters.false
Output object

The output objects define what kind of responses are returned from your API handler and is used for the OpenAPI documentation of the response:

NameDescriptionRequired
statusA status code that your API can return.true
contentTypeThe content type header of the response.true
schemaA Zod schema describing the format of the response data. A response body not matching to the schema will lead to a TS error. true

Docs config

The docs config object can be used to customize the generated docs:

NameDescription
titleCustom page title meta tag value.
descriptionCustom page description meta tag value.
faviconUrlA URL for a custom favicon.
logoUrlA URL for a custom logo.