2.0.0 • Published 2 years ago
fastify-route-group v2.0.0
fastify-route-group
Grouping and inheritance of routes
Installation
npm i fastify-route-groupor
yarn add fastify-route-groupUsage
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 |