- Fastify + Typebox + TypeScript
- Generated Swagger Schema based on registered routes and Typebox schemas
- Swagger UI
npm run start
and then, via httpie or cURL:- GET all users
http localhost:8080/users?name=Taylor
- CREATE new user
http POST localhost:8080/users name=Alex
- Check the generate Schema:
http GET http://localhost:8080/docs/json
- View the Swagger UI
- GET all users
- Take care to always add routes inside a
.register
block. Otherwise swagger does not seem to pick up on them.
npm init -y
npm i fastify
npm i -D typescript @types/node ts-node
npx tsc --init
and configureoutdir: "dist"
,"target": "es2017"
and other smaller things.mkdir src && touch src/index.ts
and put code from fastify swagger.- Add
"build": "tsc"
and"start": "ts-node src/server.ts"
to package.json. npm i @sinclair/typebox @fastify/type-provider-typebox @fastify/swagger
and add /users with schema to src/index.ts according to the official docs