feat: add multithreaded factorial computation endpoint to fastify
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 11 Aug 2023 17:15:43 +0000 (19:15 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 11 Aug 2023 17:15:43 +0000 (19:15 +0200)
example

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
examples/typescript/http-server-pool/fastify/requests.sh
examples/typescript/http-server-pool/fastify/src/main.ts

index e5ad31b3d3358d898e4e65e955f11bf417f64d42..1438f0c369fa8849e3965fa6869414962e5f66cb 100755 (executable)
@@ -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
index a681d026735d57a3bdc4dc3328990c74cb4050f8..5bf714aaf0c300c701a2a3bd235908e7034489d7 100644 (file)
@@ -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 })