JSON REST API

Fastify Integration

json-rest-api now ships a Fastify-oriented connector:

import fastify from 'fastify'
import {
  RestApiPlugin,
  RestApiKnexPlugin,
  FastifyPlugin
} from 'json-rest-api'

const app = fastify()

await api.use(RestApiPlugin, {
  simplifiedApi: false,
  simplifiedTransport: false
})

await api.use(RestApiKnexPlugin, { knex })

await api.use(FastifyPlugin, {
  app,
  mountPath: '/api'
})

What the connector does

The Fastify connector listens to the same addRoute hook as the Express connector and registers the generated REST routes on the Fastify instance you pass in pluginOptions.app.

It also consumes the transport schema exported by json-rest-schema before the request reaches the resource method:

Those field schemas are wrapped in the JSON:API document envelope expected by json-rest-api.

What gets rejected early

Fastify can now stop malformed write payloads before they reach the app layer:

The transport schema also reflects the existing write contract:

This keeps Fastify transport validation aligned with the same transport rules already enforced by the runtime methods.

Content types

The connector registers an application/vnd.api+json parser and rejects unsupported write content types before the route handler runs.

Accepted write content types are:

Scope

This connector is intentionally narrow:

The goal is transport-level shape rejection, not a second validation system.