---
title: "Fastify v5 Plugin"
description: "Generate Fastify v5 route handlers from OpenAPI with the Fastify plugin for openapi-ts. Fully compatible with validators, transformers, and all core features."
url: "https://heyapi.dev/docs/openapi/typescript/plugins/fastify"
---

Beta [Leave feedback](https://github.com/hey-api/openapi-ts/issues) · [Contribute](https://heyapi.dev/openapi-ts/community/contributing)

### About

[Section titled “About”](#about)

[Fastify](https://fastify.dev) is a fast and low overhead web framework for Node.js.

The Fastify plugin for Hey API generates route handlers from your OpenAPI spec, fully compatible with all core features.

### Collaborators

[Section titled “Collaborators”](#collaborators)

* [![Jacob Cohen](https://heyapi.dev/_astro/jacobinu_Zxpksp.webp) Jacob Cohen](https://github.com/jacobinu)

## Features

[Section titled “Features”](#features)

* Fastify v5 support
* seamless integration with `@hey-api/openapi-ts` ecosystem
* type-safe route handlers
* minimal learning curve thanks to extending the underlying technology

## Installation

[Section titled “Installation”](#installation)

In your [configuration](https://heyapi.dev/openapi-ts/get-started), add `fastify` to your plugins and you’ll be ready to generate Fastify artifacts. 🎉

openapi-ts.config.ts

```js
export default {
  input: 'hey-api/backend', // sign up at app.heyapi.dev
  output: 'src/client',
  plugins: [
    // ...other plugins
    'fastify',
  ],
};
```

## Output

[Section titled “Output”](#output)

The Fastify plugin will generate the following artifacts, depending on the input specification.

## Route Handlers

[Section titled “Route Handlers”](#route-handlers)

Route handlers are generated from all endpoints. The generated interface follows the naming convention of SDK functions.

* example

  fastify.gen.ts

  ```ts
  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 });
  ```

* config

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      'fastify',
    ],
  };
  ```

## API

[Section titled “API”](#api)

You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/fastify/types.ts) interface.

## Examples

You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples) or on [GitHub](https://github.com/hey-api/openapi-ts/tree/main/examples/openapi-ts-fastify).
