An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# template-router

[![Known Vulnerabilities](https://snyk.io/test/github/p7g/template-router/badge.svg?targetFile=package.json)](https://snyk.io/test/github/p7g/template-router?targetFile=package.json)
[![Build Status](https://travis-ci.com/p7g/template-router.svg?branch=master)](https://travis-ci.com/p7g/template-router)
[![codecov](https://codecov.io/gh/p7g/template-router/branch/master/graph/badge.svg)](https://codecov.io/gh/p7g/template-router)
[![Maintainability](https://api.codeclimate.com/v1/badges/3b035a6d7ca177fd1f59/maintainability)](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);
```