# TypeBox के साथ Type Providers — Fastify: High-Performance Node.js APIs बनाना

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

> TypeBox से schemas एक बार define करें और अपने Fastify handlers में validation के साथ TypeScript types पाएँ।

## एक schema, दो लाभ

JSON Schema और TypeScript types अलग-अलग लिखने से अंतर आ जाता है। `@fastify/type-provider-typebox` जैसा **type provider** schema से handler types निकालता है, इसलिए validation और types हमेशा मेल खाते हैं।

## Typed route

Schema request को validate करता है और `request.body` को type भी देता है।

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

Response schemas भी रखें: वे serialization तेज़ करते हैं और अनजाने data leaks रोकते हैं।
