Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aichholzer/trafico
🚥 Awesome -zero dependency- router for Express.
https://github.com/aichholzer/trafico
express rest rest-api router routing traffic
Last synced: 25 days ago
JSON representation
🚥 Awesome -zero dependency- router for Express.
- Host: GitHub
- URL: https://github.com/aichholzer/trafico
- Owner: aichholzer
- License: mit
- Created: 2017-11-15T05:27:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-23T11:44:39.000Z (over 4 years ago)
- Last Synced: 2024-04-24T19:22:41.918Z (7 months ago)
- Topics: express, rest, rest-api, router, routing, traffic
- Language: JavaScript
- Homepage:
- Size: 206 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm version](https://badge.fury.io/js/trafico.svg)](https://badge.fury.io/js/trafico)
[![Downloads](https://img.shields.io/npm/dt/trafico.svg)](https://www.npmjs.com/package/trafico)
[![Build Status](https://travis-ci.org/aichholzer/trafico.svg?branch=master)](https://travis-ci.org/aichholzer/trafico)
[![Coverage Status](https://coveralls.io/repos/github/aichholzer/trafico/badge.svg?branch=master)](https://coveralls.io/github/aichholzer/trafico?branch=master)
[![codebeat badge](https://codebeat.co/badges/05bcb301-f614-4c2c-892a-557253770e85)](https://codebeat.co/projects/github-com-aichholzer-trafico-master)
[![Greenkeeper badge](https://badges.greenkeeper.io/aichholzer/trafico.svg)](https://greenkeeper.io/)##### 🚥 Awesome -zero dependency- router for Express.
`Tráfico` will map routes to controllers and enable them in your Express application, so you don't have to do it manually and for each one. This provides an easier abstraction and enables a _drop-in-and-use_ route/controller setup.
### Basic use
```js
const express = require('express');
const Trafico = require('trafico');const app = express();
const trafico = new Trafico({
express,
routes: `/path/to/routes`,
controllers: `/path/to/controllers`
});app.use(trafico.route());
app.listen(port, () => {
console.log(`Up on port: ${port}`);
});
```### Routes
In your `routes` folder (`/path/to/routes`) create the routes you need to be mapped to your application. For example:
```
| path/to/routes
| home.js
| user.js
```The `home.js` route would look similar to this (define your routes as you normally would in your Express application):
```js
module.exports = (router, controller) => {
router.get('/', controller.index);
router.get('/date', controller.date);return router;
};
```### Controllers
`Tráfico` will load all routes from the `routes path` you specify and try to look for the controllers to match them. Create your controllers in the `controllers` folder (`/path/to/controllers`). Controllers must be named like their corresponding routes.
```
| path/to/controllers
| home.js
| user.js
```The `home.js` controller would expose the methods mapped in the route:
```js
module.exports = {
index: (req, res) => {
res.send({ hello: 'world' });
},
date: (req, res) => {
res.send({ date: +new Date() });
}
};
```### Working examples
Have a look at the `/test` folder. [ExpressBoilerplate](https://github.com/aichholzer/ExpressBoilerplate) also uses `Tráfico`.
### Contribute
```
fork https://github.com/aichholzer/trafico
```### License
[MIT](https://github.com/aichholzer/trafico/blob/master/LICENSE)