Skip to content

dimonnwc3/fastify-reverse-routes

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

fastify-reverse-routes

js-standard-style Build Status

Fastify reverse routes plugin, with this you can generate path using your route name and arguments.

Install

NPM

npm i fastify-reverse-routes

Yarn

yarn add fastify-reverse-routes

Usage

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)

Reference

This plugin decorates the fastify instance with a reverse function. That function accepts following arguments:

  • name name of your route
  • arguments values to fill placeholders
  • options additional options path-to-regexp

License

Licensed under MIT.