Skip to content

TakNePoidet/fastify-route-group

Folders and files

NameName
Last commit message
Last commit date

Latest commit

032fef3 · Sep 8, 2023

History

16 Commits
Aug 5, 2021
Sep 8, 2023
Sep 8, 2023
Aug 5, 2021
Jun 27, 2021
Aug 5, 2021
Jun 27, 2021
Jun 27, 2021
Aug 5, 2021
Aug 5, 2021
Jun 27, 2021
Sep 8, 2023
Jun 28, 2021
Jun 27, 2021
Sep 8, 2023
Sep 8, 2023
Sep 8, 2023
Sep 8, 2023
Sep 8, 2023
Sep 8, 2023

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published