Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

fastify-router

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-router

[![Build Status](https://travis-ci.org/rodrigogs/fastify-router.svg?branch=master)](https://travis-ci.org/rodrigogs/fastify-router) [![Code Climate](https://codeclimate.com/github/rodrigogs/fastify-router/badges/gpa.svg)](https://codeclimate.com/github/ro

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

fastify-router

Build Status Code Climate Test Coverage Dependency Status devDependency Status

Simple fastify router.

Install

$ npm install fastify-router

Example

const fastify = require('fastify')();
const fastifyRouter = require('fastify-router');

fastify.register(fastifyRouter);

const Router = fastify.Router;

const example = [
  { // Router
    prefix: '/home',
    routes: [
      { // Route /
        method: 'GET',
        url: '/',
        schema: {
          response: {
            200: { type: 'string' },
          },
        },
        handler: (request, reply) => reply.view('/example.pug'),
      },
    ],
  },
  { // Router
    prefix: '/users',
    routes: [
      { // Route /users/
        method: 'GET',
        url: '/',
        schema: {
          response: {
            200: {
              type: 'object',
              properties: [{
                name: { type: 'string' },
              }],
            },
          },
        },
        handler: (request, reply) => reply.send([{ name: 'Example' }]),
      },
      { // Route /users/:id
        method: 'GET',
        url: '/:id',
        schema: {
          response: {
            200: {
              type: 'object',
              properties: {
                name: { type: 'string' },
              },
            },
          },
        },
        handler: (request, reply) => reply.send({ name: 'Example' }),
      },
    ],
    routers: [
      { // Router
        prefix: '/register',
        routes: [
          { // Route /users/register
            method: 'POST',
            url: '/',
            schema: {
              response: {
                200: {
                  type: 'object',
                  properties: {
                    name: { type: 'string' },
                  },
                },
              },
            },
            handler: (request, reply) => reply.send({ name: 'Example' }),
          },
        ],
      },
    ],
  },
];

Router.route(example);

FAQs

Package last updated on 03 Oct 2017

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