https://github.com/rodrigogs/fastify-router
Simple fastify router
https://github.com/rodrigogs/fastify-router
Last synced: 6 months ago
JSON representation
Simple fastify router
- Host: GitHub
- URL: https://github.com/rodrigogs/fastify-router
- Owner: rodrigogs
- License: bsd-3-clause
- Created: 2017-09-13T18:28:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-08T21:18:42.000Z (over 8 years ago)
- Last Synced: 2025-09-26T00:50:36.692Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-router
[](https://travis-ci.org/rodrigogs/fastify-router)
[](https://codeclimate.com/github/rodrigogs/fastify-router)
[](https://codeclimate.com/github/rodrigogs/fastify-router/coverage)
[](https://david-dm.org/rodrigogs/fastify-router#info=dependencies)
[](https://david-dm.org/rodrigogs/fastify-router#info=devDependencies)
Simple fastify router.
Install
-------
>```$ npm install fastify-router```
Example
-------
```javascript
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);
```