Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/routes

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/routes

A plugin for Fastify that provides a map of routes

  • 6.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@fastify/routes

CI NPM version js-standard-style

This plugin decorates a Fastify instance with routes, which is a Map of registered routes. Note that you have to await the registration of this plugin before registering any routes so that @fastify/routes can collect them.

Data Structure

The fastify.routes Map has a key for each path any route has been registered, which points to an array of routes registered on that path. There can be more than one route for a given path if there are multiple routes added with different methods or different constraints.

  {
    '/hello': [
      {
        method: 'GET',
        url: '/hello',
        schema: { ... },
        handler: Function,
        prefix: String,
        logLevel: String,
        bodyLimit: Number,
        constraints: undefined,
      },
      {
        method: 'POST',
        url: '/hello',
        schema: { ... },
        handler: Function,
        prefix: String,
        logLevel: String,
        bodyLimit: Number,
        constraints: { ... },
      }
    ]
  }

Example

const fastify = require("fastify")();

(async () => {
  await fastify.register(require("@fastify/routes"));
  fastify.get("/hello", {}, (request, reply) => {
    reply.send({ hello: "world" });
  });

  fastify.listen({ port: 3000 }, (err, address) => {
    if (err) {
      console.error(err);
      return;
    }
    console.log(fastify.routes);
    /* will output a Map with entries:
    {
      '/hello': [
        {
          method: 'GET',
          url: '/hello',
          schema: Object,
          handler: <Function>,
          prefix: <String>,
          logLevel: <String>,
          bodyLimit: <Number>
        }
      ]
    }
    */
  });
})();

License

MIT License

Keywords

FAQs

Package last updated on 10 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc