easy-simple-router

Easily make Express.js router setups

Usage no npm install needed!

<script type="module">
  import easySimpleRouter from 'https://cdn.skypack.dev/easy-simple-router';
</script>

README

Easy Simple Router

This package was made to make adding routes easy and simple.

routes = {
  "/": {
    "GET /": sendMessage("This is my api"),
    "/math": {
      "GET /": sendMessage("This does math"),
      "POST /multiply-numbers": multiplyNumbers,
      "POST /add-numbers": addNumbers,
    },
  },
  "ALL *": sendMessage("Invalid Route")
};
router.use( "/", require("easy-simple-router")(routes) );

Getting Started

Install

npm install easy-simple-router

Usage

The image above mostly explains it. There is an example project on GitHub. Extra info:

  • Put the http method and url as the key (ex. "GET /") and the function you want to call as the value.
  • You can put any number of http methods by seperating them with "/" (ex. "GET/POST /").
  • If you don't put an http method (ex. "/") you can nest.