1.1.2 • Published 1 year ago

mfastrest v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

mfastrest

A package that makes it easy, fast and fun to create REST endpoints in ExpressJS

Installation

Using npm:

$ npm install --save msfastrest

Usage

Create a new NPM ExpressJS application, if you don't have one already.

$ npm init .
$ npm install --save express mfastrest

Create your app.js

Create the app.js using expres and mfastrest

const express = require('express');
const bodyParser = require('body-parser');

const { setupFastRest, getRegisteredRoutes, getRegisteredRoutesAsDotNetHashTable } = require('mfastrest');

const app = express();

app.use(bodyParser.json());

setupFastRest(app, __dirname + "/testFns", "v1");

console.log(getRegisteredRoutes());
const port = process.env.PORT || 3001;

app.listen(port, function() {
        console.log('\n\n:) Server is listening on port: ' + port + '\n');
});

Now, make your functions

$ mkdir testFns

Make a javscript file like testFns/hello.js

module.exports.hello = {
        name: 'Hello World',
        route: 'hello',
        verb: 'get',
        fn: async (body, params, req) => {
                return {response: "hello"};
        }
};
module.exports.world = {
        name: 'Hello World',
        route: 'hello-world',
        verb: 'get',
        // also supports scopes: for an express-oauth2-jwt-bearer
        fn: async (body, params, req) => {
                return {response: "hello world"};
        }
};
1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago