Fastify starter
A JSON API with Fastify and schema validation.
Open in editor Free. Runs in your browser, no sign-up.
- fastify
Fastify
The code
Two files, exactly what you get in the editor.
import Fastify from 'fastify'
const app = Fastify({ logger: true })
app.get('/', async () => ({ hello: 'world', try: '/add?a=2&b=3' }))
app.get(
'/add',
{
schema: {
querystring: {
type: 'object',
required: ['a', 'b'],
properties: { a: { type: 'number' }, b: { type: 'number' } },
},
},
},
async (request) => {
const { a, b } = request.query as { a: number; b: number }
return { a, b, sum: a + b }
},
)
const port = Number(process.env.PORT) || 3000
await app.listen({ port, host: '0.0.0.0' })
Questions
Can I run Fastify in the browser?
Yes. Press Run and the program runs in a Node.js-compatible runtime, compiled to WebAssembly, right in your browser tab. npm packages install in the browser too.
How do I start a Fastify project online?
Click Open in editor. jsdrop copies this starter into a new drop with index.ts and package.json. Press Run to start it, and edit as you go.
Can other people reach my server?
Yes. When the program calls listen(), the preview shows the server and a public tunnel URL that works while your tab runs it. With Pro, deploy the drop to run around the clock at its own address.
Is it free?
Yes. Public drops, running in the browser, live collaboration, versions, and embeds are free, and you do not need an account to start.