This library is just a wrapper on Express. It helps you making REST APIs.
Oh, that's pretty simple.
I'll include some code from examples/01.js
.
const express = require('express');
const rapijs = require('rapijs');
const app = express();
let myResource = rapijs.Resource({
read: { customUrlParams: [], cb: (req, res) => {
res.send({
greeting: "Hi!"
});
}},
create: { customUrlParams: [], cb: () => {}}
update: { customUrlParams: [], cb: () => {}}
del : { customUrlParams: [], cb: () => {}}
});
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/', myResource);
app.listen(8080);
- It loads the
express
andrapijs
modules. - It creates an instance of Express app.
- It creates a
rapijs
resource:
Read: no custom URL parameters, callback sends greeting.
Create: no custom URL parameters, callback does nothing.
Update: no custom URL parameters, callback does nothing.
Delete: no custom URL parameters, callback does nothing. - The app uses the JSON
middleware
provided by Express. - The app uses the URL encoding
middleware
too. - The app sets the resource to be on
/
path. - The app listens on
localhost:8080
.
A resource is an object we're passing to Resource function to create a router.
Basically, it has four methods (callbacks) to belong to CRUD:
- Create
- Read
- Update
- Delete
Find me on GitHub!