https://github.com/p7g/template-router
A DSL for routing based on tagged template literals
https://github.com/p7g/template-router
es2015 es6 express koa nodejs routing template-literals
Last synced: 2 months ago
JSON representation
A DSL for routing based on tagged template literals
- Host: GitHub
- URL: https://github.com/p7g/template-router
- Owner: p7g
- License: mit
- Created: 2019-02-15T15:41:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-15T21:39:27.000Z (over 7 years ago)
- Last Synced: 2025-10-28T12:31:26.574Z (8 months ago)
- Topics: es2015, es6, express, koa, nodejs, routing, template-literals
- Language: JavaScript
- Size: 77.1 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# template-router
[](https://snyk.io/test/github/p7g/template-router?targetFile=package.json)
[](https://travis-ci.com/p7g/template-router)
[](https://codecov.io/gh/p7g/template-router)
[](https://codeclimate.com/github/p7g/template-router/maintainability)
Define routes for express, koa-router or similar using tagged template literals.
## Example
```js
const express = require('express');
const routes = require('template-router');
const app = express();
routes(app)`
GET /hello/:name ${
function sayHello(req, res) {
const name = req.params.name;
res.send(`Hello, ${name}`);
}
}
POST ${/some regex/} ${
function doPostThing(req, res) {
// ...
}
}
`;
app.listen(8080);
```