1.0.6 • Published 5 years ago

express-rest-ctrl v1.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

How to use

After install the express-rest-ctrl you need to create the controllers folder inside you root project

$ mkdir controllers

So, after create the controllers folder, lets create a controller thats called User for example.

class User{
    get(req,res,next){
            res.send({works: true})
    }

    post(req,res,next) {
            res.send('Welcome to post method')
    }
}

module.exports = User;

Inside controllers folder we can create subfolders and inside all the controllers with this structure ControllerName.controller.js

How you see the class has two methods, get and post, so let's registry this class as a controller and let's see what happen.

Inside you server file, lets add this little code.

const Server = require('express-rest-ctrl') //get the pk;
const app = Server.create() // Let's create the server

app.addRoute('/users', 'User') //Add the route and they controller
app.run() // Run the server

That's it, as you see we have only four lines of code, all of rest is managed by express-rest-ctrl

Response examples:

Drag Racing

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago