1.2.0 • Published 7 years ago
express-rest-service v1.2.0
express.rest.service
Create REST service for publishing with express
Installation
npm install express-rest-serviceUsage
const ExpressRESTService = require("express-rest-service");require express-rest-service
const myRESTService = new ExpressRESTService(props);create REST service instance with properties
const app = express();create express app
app.get('/foo', (req, res) => myRESTService.call(req, res));register service in express app
Properties
argsobject with keys that represent request argunents to servicefnfunction that will be called on service call with arguments (service, request, response)hasAccessfunction that will be called with arguments (service, request, callback) to check is user logged in or has user access to this service or not. function should call callback with 2 boolean arguments (loggedIn, hasAccess)prettyJSONboolean false by default
Example
const myRESTService = new ExpressRESTService({
args: {
firstName: false,
lastName: true,
age: "number",
height: {
type: "number",
mandatory: true,
decimalPrecision: 2
}
},
fn: (service, request, response) => {
service.success({
data: service.args
});
}
});
app.get('/foo', (req, res) => myRESTService.call(req, res));