quirrel
quirrel copied to clipboard
Fastify Plugin
I will be using Fastify for my internal and external API, so a native Fastify plugin would be great.
I know that Quirrel is no longer being worked on, but was just hoping this simple little thing could be implemented.
Quirrel is being worked on - we're shutting down the hosted version, but you can continue to self-host and use it :D
A Fastify plugin sounds like a great idea. I haven't worked a lot with Fastify, so I don't really know how a idiomatic plugin would look. It should be pretty easy to write an adapter using QuirrelClient
, though. Here's a snippet on how QuirrelClient
is used:
import { QuirrelClient } from "quirrel"
const fastify = ...
const FooQueue = new QuirrelClient({
route: "/queues/foo",
async handler(job: { message: string }) {
console.log("Here's a message from the foo queue:", job.message);
},
});
fastify.post("/queues/foo", async (request, reply) => {
const { body, headers, status } = await FooQueue.respondTo(
request.body,
request.headers
);
reply.status(status).headers(headers).send(body);
});
// ...
FooQueue.enqueue(...)
The important bit really is that route
is the same between the QuirrelClient and the fastify route, and that you implement .respondTo
.
What do you think about adapting this snippet into a Fastify Plugin that makes sense for your project, and commenting it back here? If you have more experience with Fastify than me, I'd love to take your intuition here as a basis for the "official" Quirrel/Fastify plugin :)