Menu

Post image 1
Post image 2
1 / 2
0

Fastify Has a Free API You Should Know About

DEV Community: fastify·Alex Spinov·3 days ago
#I7iySNiA
#dev#fastify#type#request#async#user
Reading 0:00
15s threshold

Fastify is the fastest Node.js web framework, and its plugin architecture makes it far more than a simple HTTP server. Core API — Speed Meets Simplicity import Fastify from ' fastify ' const fastify = Fastify ({ logger : true }) fastify . get ( ' /api/users ' , async ( request , reply ) => { const { limit = 10 , offset = 0 } = request . query return db . user . findMany ({ take : limit , skip : offset }) }) fastify . post ( ' /api/users ' , { schema : { body : { type : ' object ' , required : [ ' name ' , ' email ' ], properties : { name : { type : ' string ' }, email : { type : ' string ' , format : ' email ' } } } } }, async ( request ) => { return db . user . create ({ data : request . body }) }) await fastify .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More