fastifyApiUi
Fastify plugin factory that mounts the @opra/api-ui reference page as a Fastify plugin, registered with app.register().
import { fastifyApiUi } from '@opra/api-ui';
Signature
function fastifyApiUi(
document: ApiDocument,
options?: ApiUiOptions,
): FastifyPluginAsync
Returns a Fastify plugin (compatible with app.register(plugin, { prefix })).
Usage
import Fastify from 'fastify';
import { fastifyApiUi } from '@opra/api-ui';
const app = Fastify();
app.register(fastifyApiUi(apiDocument, {
pageTitle: 'My API',
}), { prefix: '/reference' });
With scope selector
app.register(fastifyApiUi(apiDocument, {
scopes: ['public', 'internal'],
}), { prefix: '/reference' });
// GET /reference/public/ → public scope
// GET /reference/internal/ → internal scope
Fastify specifics
Unlike Express, Fastify does not strip the mount prefix from req.url. fastifyApiUi reads the full prefix from instance.prefix (which includes all parent prefixes) and passes it to the underlying handler correctly. Responses are delivered via reply.hijack() on the raw Node.js socket, bypassing Fastify's serialization.
See also
expressApiUi— Express equivalentApiUiOptions