bedrock-rest
A bedrock module that adds helpers for REST support.
Requirements
- npm v3+
Quick Examples
npm install bedrock-rest
var bedrock = ;var brIdentity = ;var brPassport = ;var brRest = ;var cors = ;var myItems = ; bedrockevents; bedrockevents; { var idPath = bedrockconfigidentitybasePath + '/:identity'; app; appoptionsidPath + '/items' ; app; appoptionsidPath + '/items/:item' ; app;}
API
idParam(req, res, next, id)
Validates an ID from a URL path and, it passes validation, it will be available via req.params. This method is for use with express or bedrock-express:
// passed to an express server's param callserver; // setup with "bedrock-express.init" eventbedrockevents;
makeResourceHandler(options)
Make middleware for a type negotiated REST resource. This middleware handles
the details of handling requests for json
, application/ld+json
, and
html
. JSON based requests will just return the data from the get
option.
HTML requests default to using another route to return HTML. It defaults to
main.html
which could be setup to start a single page app that calls the
same endpoint to get the JSON based resource.
options
:
- validate: content to pass to bedrock.validation.validate
- get(req, res, callback(err, data)): get resource data
- json: handle JSON content types (false, true, 'route') (default: true)
- html: handle HTML content types (false, 'route') (default: 'route')
linkedDataHandler(options)
Alias for makeResourceHandler.
when.prefers.jsonld
Middleware to check if request prefers JSON-LD
when.prefers.ld
Middleware to check if request prefers linked data.