A collection of core restify plugins
Install the module with: npm install restify-plugins
This is the core set of plugins that restify ships with. These include lots of header parsing handlers, data parsing handlers, as well as other useful logging/metrics handlers.
This module includes the follow pre plugins, which are intended to be used
prior to the routing of a request:
sanitizePath()- cleans up duplicate or trailing / on the URLcontext()- Provide req.set(key, val) and req.get(key) methods for setting and retrieving context to a specific request.userAgent(options)- used to support edge cases for HEAD requests when using curloptions.userAgentRegExp{RegExp} regexp to capture curl user-agents
strictQueryParams()- checks req.urls query params with strict key/val format and rejects non-strict requests with status code 400.options.message{String} response body message string
This module includes the following header parser plugins:
acceptParser(accepts)- Accept headeraccepts{Array} an array of acceptable types
authorizationParser(options)- Authorization headeroptions{Object} options object passed to http-signature module
conditionalRequest()- Conditional headers (If-*)fullResponse()- handles disappeared CORS headers
This module includes the following data parsing plugins:
auditLogger(options)- an audit logger for recording all handled requestsoptions.log{Object} bunyan loggeroptions.body{?}
bodyParser(options)- parses POST bodies toreq.body. automatically uses one of the following parsers based on content type:urlEncodedBodyParser(options)- parses url encoded form bodiesjsonBodyParser(options)- parses JSON POST bodiesmultipartBodyParser(options)- parses multipart form bodies- All bodyParsers support the following options:
options.mapParams- default false. copies parsed post body values onto req.paramsoptions.overrideParams- default false. only applies when if mapParams true. when true, will stomp on req.params value when existing value is found.
jsonp()- parses JSONP callbackqueryParser()- Parses URL query paramters intoreq.query. Many options correspond directly to option defined for the underlyingqs.parse.options.mapParams- Default false. Copies parsed query parameters intoreq.params.options.overrideParams- Default false. Only applies when if mapParams true. When true, will stomp on req.params field when existing value is found.options.allowDots- Default false. Transform?foo.bar=bazto a nested object:{foo: {bar: 'baz'}}.options.arrayLimit- Default 20. Only transform?a[$index]=bto an array if$indexis less thanarrayLimit.options.depth- Default 5. The depth limit for parsing nested objects, e.g.?a[b][c][d][e][f][g][h][i]=j.options.parameterLimit- Default 1000. Maximum number of query params parsed. Additional params are silently dropped.options.parseArrays- Default true. Whether to parse?a[]=b&a[1]=cto an array, e.g.{a: ['b', 'c']}.options.plainObjects- Default false. Whetherreq.queryis a "plain" object -- does not inherit fromObject. This can be used to allow query params whose names collide with Object methods, e.g.?hasOwnProperty=blah.options.strictNullHandling- Default false. If true,?a&b=results in{a: null, b: ''}. Otherwise,{a: '', b: ''}.
requestLogger(options)- adds timers for each handler in your request chainoptions.properties{Object} properties to pass to bunyan'slog.child()method
The module includes the following response plugins:
-
dateParser(delta)- expires requests based on current time + deltadelta{Number} age in seconds
-
gzip(options)- gzips the response if client accepts itoptions{Object} options to pass to zlib
-
serveStatic()- used to serve static files -
throttle(options)- throttles responsesoptions.burst{Number}options.rate{Number}options.ip{Boolean}options.username{Boolean}options.xff{Boolean}options.overrides{Object}
-
requestExpiry(options)- A request expiry will use headers to tell if the incoming request has expired or not. There are two options for this plugin:- Absolute Time
- Time in Milliseconds since the Epoch when this request should be considered expired
- Timeout
- The request start time is supplied
- A timeout, in milliseconds, is given
- The timeout is added to the request start time to arrive at the absolute time in which the request is considered expires
options.absoluteHeader{String} header name of the absolute time for request expirationoptions.startHeader{String} header name for the start time of the requestoptions.timeoutHeader{String} The header name for the time in milliseconds that should ellapse before the request is considered expired.
- Absolute Time
Add unit tests for any new or changed functionality. Ensure that lint and style checks pass.
To start contributing, install the git pre-push hooks:
make githooksBefore committing, run the prepush hook:
make prepushIf you have style errors, you can auto fix whitespace issues by running:
make codestyle-fixCopyright (c) 2015 Alex Liu
Licensed under the MIT license.