From 16100564e5a2c09f14a884eb61fdf57bfd38914a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 11 Aug 2023 19:15:43 +0200 Subject: [PATCH] feat: add multithreaded factorial computation endpoint to fastify example MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../typescript/http-server-pool/fastify/requests.sh | 6 ++++++ .../typescript/http-server-pool/fastify/src/main.ts | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) 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 }) -- 2.34.1