/template-router

A DSL for routing based on tagged template literals

Primary LanguageJavaScriptMIT LicenseMIT

template-router

Known Vulnerabilities Build Status codecov Maintainability

Define routes for express, koa-router or similar using tagged template literals.

Example

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);