Fastify ​
WARNING
Fastify plugin is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on GitHub.
Fastify is a fast and low overhead web framework for Node.js.
Features ​
- seamless integration with
@hey-api/openapi-ts
ecosystem - type-safe route handlers
- minimal learning curve thanks to extending the underlying technology
Installation ​
WARNING
Fastify plugin works only with the experimental parser which is currently an opt-in feature.
Ensure you have already configured @hey-api/openapi-ts
. Update your configuration to use the Fastify plugin.
export default {
client: '@hey-api/client-fetch',
experimentalParser: true,
input: 'path/to/openapi.json',
output: 'src/client',
plugins: [
// ...other plugins
'fastify',
],
};
You can now generate Fastify artifacts. 🎉
Output ​
The Fastify plugin will generate the following artifacts, depending on the input specification.
Route Handlers ​
Route handlers are generated from all endpoints. The generated interface follows the naming convention of SDK functions.
const fastify = Fastify();
const serviceHandlers: RouteHandlers = {
createPets(request, reply) {
reply.code(201).send();
},
listPets(request, reply) {
reply.code(200).send([]);
},
showPetById(request, reply) {
reply.code(200).send({
id: Number(request.params.petId),
name: 'Kitty',
});
},
};
fastify.register(glue, { serviceHandlers });
Examples ​
You can view live examples on StackBlitz.
Sponsoring ​
Love Hey API? Please consider becoming a sponsor.