From: Jérôme Benoit Date: Fri, 11 Aug 2023 17:15:43 +0000 (+0200) Subject: feat: add multithreaded factorial computation endpoint to fastify X-Git-Tag: v2.6.23~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=16100564e5a2c09f14a884eb61fdf57bfd38914a;p=poolifier.git feat: add multithreaded factorial computation endpoint to fastify example Signed-off-by: Jérôme Benoit --- diff --git a/examples/typescript/http-server-pool/fastify/requests.sh b/examples/typescript/http-server-pool/fastify/requests.sh index e5ad31b3..1438f0c3 100755 --- a/examples/typescript/http-server-pool/fastify/requests.sh +++ b/examples/typescript/http-server-pool/fastify/requests.sh @@ -6,3 +6,9 @@ for ((request=1;request<=60;request++)) do time curl -i -H "Content-Type: application/json" -X POST -d '{"key1":"value1", "key2":"value2"}' http://localhost:8080/api/echo done + + +for ((request=1;request<=60;request++)) +do + time curl -i http://localhost:8080/api/factorial/30 +done diff --git a/examples/typescript/http-server-pool/fastify/src/main.ts b/examples/typescript/http-server-pool/fastify/src/main.ts index a681d026..5bf714aa 100644 --- a/examples/typescript/http-server-pool/fastify/src/main.ts +++ b/examples/typescript/http-server-pool/fastify/src/main.ts @@ -31,10 +31,14 @@ fastify.all('/api/echo', async (request, reply) => { await reply.send((await fastify.execute({ body: request.body }, 'echo')).body) }) -// fastify.get('/api/factorial/:number', async (request, reply) => { -// const { number } = request.params -// await reply.send((await fastify.execute({ body: { number } }, 'factorial')).body) -// }) +fastify.get<{ + Params: { number: number } +}>('/api/factorial/:number', async (request, reply) => { + const { number } = request.params + await reply.send( + (await fastify.execute({ body: { number } }, 'factorial')).body + ) +}) try { await fastify.listen({ port })