The easiest way to render a beautiful API reference with Fastify. All based on your OpenAPI/Swagger document.
npm install @scalar/fastify-api-reference
And then register it with Fastify:
await fastify.register(require('@scalar/fastify-api-reference'), {
routePrefix: '/reference',
})
If you have a OpenAPI/Swagger document already, you can pass an URL to the plugin:
// Render an API reference for a given OpenAPI/Swagger spec URL
fastify.register(require('@scalar/fastify-api-reference'), {
routePrefix: '/reference',
configuration: {
title: 'Our API Reference',
spec: {
url: '/openapi.json',
},
},
})
With [@fastify/swagger], we’re picking it up automatically, so this would be enough:
await fastify.register(require('@scalar/fastify-api-reference'), {
routePrefix: '/reference',
})
We wrote a detailed integration guide for Fastify.
The fastify plugin takes our universal configuration object, read more about configuration in the core package README.
By default, we’re using a custom Fastify theme and it’s beautiful. But you can choose one of our other themes, too:
await fastify.register(require('@scalar/fastify-api-reference'), {
routePrefix: '/reference',
configuration: {
theme: 'purple',
},
})
The plugin is compatible with the Fastify logger. You can configure the log level for the routes registered by the plugin:
fastify.register(require('@scalar/fastify-api-reference'), {
routePrefix: '/reference',
logLevel: 'silent',
})
We are API nerds. You too? Let’s chat on Discord: https://discord.gg/scalar
The source code in this repository is licensed under MIT.