Skip to content

Latest commit

 

History

History
346 lines (164 loc) · 7.85 KB

DOCUMENTATION.md

File metadata and controls

346 lines (164 loc) · 7.85 KB

getFor(optns)

Create http get handler for given service options

Parameters
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
Examples
const { app, getFor } = require('@lykmapipo/express-rest-actions');

const get = (query, done) => done(null, { data:[ ... ] });
app.get('/v1/users', getFor({ get }));
Returns
  • Function valid express middleware to handle get request

schemaFor(optns)

Create http get handler for schema of a given service options

Parameters
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
Examples
const { app, schemaFor } = require('@lykmapipo/express-rest-actions');

const getSchema = (query, done) => done(null, { ... });
app.get('/v1/users', schemaFor({ getSchema }));
Returns
  • Function valid express middleware to handle get schema request

downloadFor(optns)

Create http get handler for downloading of a given service options

Parameters
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 and
fileName which is String.
 
optns.filterParams=true Boolean whether to merge params into filter Optional
Examples
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 }));
Returns
  • Function valid express middleware to handle downloading request

getByIdFor(optns)

Create http getById handler for given service options

Parameters
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
Examples
const { app, getByIdFor } = require('@lykmapipo/express-rest-actions');

const getById = (query, done) => done(null, { ... });
app.get('/v1/users/:id', getByIdFor({ getById }));
Returns
  • Function valid express middleware to handle get by id request

postFor(optns)

Create http post handler for given service options

Parameters
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
Examples
const { app, postFor } = require('@lykmapipo/express-rest-actions');

const post = (body, done) => done(null, { ... });
app.post('/v1/users', postFor({ post }));
Returns
  • Function valid express middleware to handle post request

patchFor(optns)

Create http patch handler for given service options

Parameters
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
Examples
const { app, patchFor } = require('@lykmapipo/express-rest-actions');

const patch = (query, done) => done(null, { ... });
app.patch('/v1/users/:id', patchFor({ patch }));
Returns
  • Function valid express middleware to handle patch request

putFor(optns)

Create http put handler for given service options

Parameters
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
Examples
const { app, putFor } = require('@lykmapipo/express-rest-actions');

const put = (query, done) => done(null, { ... });
app.put('/v1/users/:id', putFor({ put }));
Returns
  • Function valid express middleware to handle put request

deleteFor(optns)

Create http delete handler for given service options

Parameters
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
Examples
const { app, deleteFor } = require('@lykmapipo/express-rest-actions');

const del = (query, done) => done(null, { ... });
app.delete('/v1/users/:id', deleteFor({ del }));
Returns
  • Function valid express middleware to handle delete request

routerFor(optns)

Create http resource router for given service options

Parameters
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 and
fileName 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
Examples
const { app, routerFor } = require('@lykmapipo/express-rest-actions');

const options = { get: ..., post: ..., del: ... };
app.use(routerFor(options));
Returns
  • Function valid express middleware to handle router request

Documentation generated with doxdox.