> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pagamentos.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Fastify

> Integrando o Fastify com o **pagamentos.dev**

## O que é Fastify?

Fastify é um framework web altamente performático e de baixo overhead para
Node.js, focado em fornecer a melhor experiência de desenvolvimento.

Visite o site oficial do [Fastify](https://fastify.dev/) para saber mais.

## Instalação

Para começar o desenvolvimento, instale a biblioteca com seu gerenciador de
pacotes favorito:

<CodeGroup>
  ```bash npm theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  npm i pagamentos
  ```

  ```bash Yarn theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  yarn add pagamentos
  ```

  ```bash pnpm theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  pnpm add pagamentos
  ```

  ```bash Bun theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  bun i pagamentos
  ```
</CodeGroup>

## Integração com Fastify

Para receber webhooks do **pagamentos.dev** usando Fastify, você pode usar o
adaptador `toFastify` que converte o handler de webhooks para ser compatível
com o framework.

```ts server.ts theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import Fastify from 'fastify'
import { toFastify } from 'pagamentos/fastify'
import { pg } from './pagamentos'

const fastify = Fastify()

fastify.post('/webhook', toFastify(pg.webhooks.handler))

fastify.listen({ port: 3000 })
```

> Confira um exemplo completo de API com Fastify + Mercado Pago em:
> [github.com/pagamentosdev/pagamentos/blob/main/examples/with-fastify/src/index.ts](https://github.com/pagamentosdev/pagamentos/blob/main/examples/with-fastify/src/index.ts)
