Skip to content

Commit 186f97a

Browse files
committed
chore(examples): improved example for fastify
1 parent c49851b commit 186f97a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

examples/with-fastify/src/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,23 @@ fastify.register(FastifySteno, {
1414
})
1515

1616
fastify.get('/', () => {
17-
const users = fastify.steno.get<Users>('users')
18-
return users?.data
17+
const users = fastify.steno.get<Users>('users')!
18+
return users.data
1919
})
2020

21-
fastify.post('/', { schema: { body: { $ref: 'User' } } }, (req) => {
22-
return req.body
21+
fastify.post<{ Body: User }>(
22+
'/',
23+
{ schema: { body: { $ref: 'User' } } },
24+
async (req) => {
25+
const users = fastify.steno.get<Users>('users')!
26+
users.data!.users.push(req.body)
27+
await users.write()
28+
return users.data
29+
}
30+
)
31+
32+
fastify.get('/schemas', () => {
33+
return fastify.getSchemas()
2334
})
2435

2536
fastify.listen({ host: '0.0.0.0', port: 3000 }, (err, address) => {

0 commit comments

Comments
 (0)