Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
Created February 1, 2021 17:59
Show Gist options
  • Save RafaelGSS/8a4932d8680512f6ba87d7e43a588422 to your computer and use it in GitHub Desktop.
Save RafaelGSS/8a4932d8680512f6ba87d7e43a588422 to your computer and use it in GitHub Desktop.
Fastify + Typebox Example
import { Type, Static } from '@sinclair/typebox';
export const SendTextMessage = Type.Object({
body: Type.String(),
chatId: Type.Number(),
options: Type.Optional(
Type.Object({ previewUrl: Type.Optional(Type.Boolean()) }),
),
});
export type SendTextMessage = Static<typeof SendTextMessage>;
import Fastify from 'fastify';
import { SendTextMessage } from './incoming-request.dto';
const fastify = Fastify();
fastify.post(
'/message',
{
schema: SendTextMessage,
handler: async (
{ body }: FastifyRequest<{ Body: SendTextMessage }>,
reply: FastifyReply,
): Promise<void> => {
reply.code(200).send({});
},
},
);
fastify.listen(3000, (err) => {
if (err) throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment