1.0.12 • Published 2 years ago

@anveeg/mini-route v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

miniRoute

npm (scoped) install size npm bundle size (scoped)

Install

$ npm i @anveeg/mini-route

Usage

Server index file

const express = require('express');
const MiniRoute = require('@anveeg/mini-route')

const app = express();

MiniRoute.api(app, [<path of controller file 1>, <path of controller file 2>, ...... <path of controller file n>])

app.listen(<port-number>, () => {});

Controller file

add the name of the controller in all your controller file's first line.

Syntax - /** @controller = <name> **/

example

/** @controller = control1 * */
const someLibrary = require('some-library');


const funtion1 = async (req, res) => {
    console.log('funtion1')
    return res.status(200).send({status: 0, message: "Messages"});
}

const function2 = async (req, res) => {
    console.log('function2')
    return res.status(200).send({status: 0, message: "Messages"});

}

module.exports = {
    funtion1,
    function2
}

Function call from client side

Here- \ 3000 is the server's port number \ control1 is name of controller file which we defined in server's controller file \ function 1 is the function defined in the controller file \ {"param1":"value1", "param2": "value2"} is the object of paramters

Note -

  1. seperate controller name and function name with a dot (.)
  2. parameters should be in an object
let reqOptions = {
  url: "http://localhost:3000/control1.function1/{"param1":"value1", "param2": "value2"}",
  method: "GET", // or POST/PUT/DELETE
  headers: headersList,
  data: bodyContent,
}

axios.request(reqOptions).then(function (response) {
  console.log(response.data);
})

License

MIT

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago