fastify-route-group
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

fastify-route-group

Grouping and inheritance of routes

Installation

npm i fastify-route-group

or

yarn add fastify-route-group

Usage

const fastify = require('fastify');
const { Router } = require('fastify-route-group');

async function bootstrap() {
  const server = fastify();
  const router = new Router(server);

  router.get('/', (_, reply) => {
    reply.send('index page');
  });

  router.namespace('api', () => {
    router.namespace('methods', () => {
      router.prefix('posts.', () => {
        router.get('get', (_, reply) => {
          reply.send('get posts from API');
        });
      });
      router.prefix('users.', () => {
        router.get('get', (_, reply) => {
          reply.send('get users from API');
        });
      });
    });
  });
  await server.listen(3000);
}

bootstrap()
  .then();

The following routes are obtained

Url Description
/ index page
/api/methods/posts.get posts api
/api/methods/users.get users api

Dependents (0)

Package Sidebar

Install

npm i fastify-route-group

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

10.7 kB

Total Files

8

Last publish

Collaborators

  • tak_ne_poidet