Fastify reverse routes plugin, with this you can generate path using your route name and arguments.
npm i fastify-reverse-routes
yarn add fastify-reverse-routes
Add it to your project with register
and you are done!
const fastify = require("fastify")()
fastify.register(require("fastify-reverse-routes").plugin)
fastify.route({
url: "/frameworks/:name",
method: "GET",
name: "frameworks",
handler: async () => {
reply.send(fastify.reverse("frameworks", { name: "fastify" })) // /frameworks/fastify
},
})
fastify.listen(3000)
This plugin decorates the fastify
instance with a reverse
function. That function accepts
following arguments:
name
name of your routearguments
values to fill placeholdersoptions
additional options path-to-regexp
Licensed under MIT.