Create http get handler for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid getFor options | |
optns.get | Function |
valid service function to invoke when get | |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
const { app, getFor } = require('@lykmapipo/express-rest-actions');
const get = (query, done) => done(null, { data:[ ... ] });
app.get('/v1/users', getFor({ get }));
Function
valid express middleware to handle get request
Create http get handler for schema of a given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid schemaFor options | |
optns.getSchema | Function |
valid service function to invoke when get schema | |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
const { app, schemaFor } = require('@lykmapipo/express-rest-actions');
const getSchema = (query, done) => done(null, { ... });
app.get('/v1/users', schemaFor({ getSchema }));
Function
valid express middleware to handle get schema request
Create http get handler for downloading of a given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid downloadFor options | |
optns.download | Function |
valid service to to invoke when downloading. It must return readStream which is stream.Readable andfileName which is String . |
|
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
const { createReadStream } = require('fs');
const { app, downloadFor } = require('@lykmapipo/express-rest-actions');
const download = (query, done) => {
const fileName = 'avatar.png';
const readStream = createReadStream('./avatar.png');
return done(null, { fileName, readStream });
};
app.get('/v1/files/avatar', downloadFor({ download }));
Function
valid express middleware to handle downloading request
Create http getById handler for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid getByIdFor options | |
optns.getById | Function |
valid service function to invoke when getById | |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
const { app, getByIdFor } = require('@lykmapipo/express-rest-actions');
const getById = (query, done) => done(null, { ... });
app.get('/v1/users/:id', getByIdFor({ getById }));
Function
valid express middleware to handle get by id request
Create http post handler for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid postFor options | |
optns.post | Function |
valid service function to invoke when post | |
optns.bodyParams=true | Boolean |
whether to merge params into body | Optional |
const { app, postFor } = require('@lykmapipo/express-rest-actions');
const post = (body, done) => done(null, { ... });
app.post('/v1/users', postFor({ post }));
Function
valid express middleware to handle post request
Create http patch handler for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid patchFor options | |
optns.patch | Function |
valid service function to invoke when patch | |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
optns.bodyParams=true | Boolean |
whether to merge params into body | Optional |
const { app, patchFor } = require('@lykmapipo/express-rest-actions');
const patch = (query, done) => done(null, { ... });
app.patch('/v1/users/:id', patchFor({ patch }));
Function
valid express middleware to handle patch request
Create http put handler for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid putFor options | |
optns.put | Function |
valid service function to invoke when put | |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
optns.bodyParams=true | Boolean |
whether to merge params into body | Optional |
const { app, putFor } = require('@lykmapipo/express-rest-actions');
const put = (query, done) => done(null, { ... });
app.put('/v1/users/:id', putFor({ put }));
Function
valid express middleware to handle put request
Create http delete handler for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid deleteFor options | |
optns.del | Function |
valid service function to invoke when delete | |
optns.soft=false | Boolean |
whether to invoke soft delete | Optional |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
const { app, deleteFor } = require('@lykmapipo/express-rest-actions');
const del = (query, done) => done(null, { ... });
app.delete('/v1/users/:id', deleteFor({ del }));
Function
valid express middleware to handle delete request
Create http resource router for given service options
Name | Type | Description | |
---|---|---|---|
optns | Object |
valid routerFor options | |
optns.resource | String |
valid resource name to be used as http path | |
optns.get | Function |
valid service function to invoke when get | |
optns.getSchema | Function |
valid service function to invoke when get schema | Optional |
optns.export | Function |
valid service function to invoke when get exports. It must return readStream which is stream.Readable andfileName which is String . |
Optional |
optns.getById | Function |
valid service function to invoke when getById | |
optns.post | Function |
valid service function to invoke when post | |
optns.patch | Function |
valid service function to invoke when patch | |
optns.put | Function |
valid service function to invoke when put | |
optns.del | Function |
valid service function to invoke when delete | |
optns.soft=false | Boolean |
whether to invoke soft router | Optional |
optns.version='1.0.0' | String |
valid api version to append on path | Optional |
optns.filterParams=true | Boolean |
whether to merge params into filter | Optional |
optns.bodyParams=true | Boolean |
whether to merge params into body | Optional |
const { app, routerFor } = require('@lykmapipo/express-rest-actions');
const options = { get: ..., post: ..., del: ... };
app.use(routerFor(options));
Function
valid express middleware to handle router request
Documentation generated with doxdox.