ZeroVocabulary / easy-simple-router

Easily make Express.js router setups

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Easily make Express.js router setups


Languages

Language:JavaScript 100.0%