# Type Providers with TypeBox — Fastify: Building High-Performance Node.js APIs

Source: https://www.geekswithgeeks.com/en/fastify/ff-type-providers

> Define schemas once with TypeBox and get validation plus TypeScript types in your Fastify handlers.

## One schema, two benefits

Writing JSON Schema and TypeScript types separately invites drift. A **type provider** such as `@fastify/type-provider-typebox` infers handler types from the schema, so validation and types always match.

## Typed route

The schema both validates the request and types `request.body`.

```typescript
import Fastify from 'fastify';
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';

const app = Fastify().withTypeProvider<TypeBoxTypeProvider>();

app.post('/items', {
  schema: { body: Type.Object({ name: Type.String(), price: Type.Number({ minimum: 0 }) }) },
}, async (req) => {
  return { name: req.body.name.toUpperCase() }; // req.body is typed
});
```

Keep response schemas too: they speed up serialization and stop accidental data leaks.
