
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
osprey-method-handler
Advanced tools
Middleware for validating requests and responses based on a RAML method object
Middleware for validating requests and responses based on a RAML method object.
npm install osprey-method-handler --save
formParameters
(ignores undocumented parameters)formParameters
(ignores undocumented parameters)Please note: Due to the build time of libxmljs
, it does not come bundled. If you need XML validation, please install libxmljs
as a dependency of your own project.
const express = require('express')
const handler = require('osprey-method-handler')
const utils = require('./utils')
const app = express()
// webapi-parser.Operation
const methodObj = utils.getMethodObj()
const options = {}
app.post(
'/users',
handler(methodObj, '/users', 'POST', options),
function (req, res) {
res.send('success')
}
)
Accepts webapi-parser Operation
object as first argument, path string as second argument, method name as third and options object as final argument.
Options
ajv
Custom Ajv instance to be used to validate query strings, request headers and request bodied (url-encoded, form-data, json)discardUnknownBodies
Discard undefined request streams (default: true
)discardUnknownQueryParameters
Discard undefined query parameters (default: true
)discardUnknownHeaders
Discard undefined header parameters (always includes known headers) (default: true
)parseBodiesOnWildcard
Toggle parsing bodies on wildcard body support (default: false
)reviver
The reviver passed to JSON.parse
for JSON endpointslimit
The maximum bytes for XML, JSON and URL-encoded endpoints (default: '100kb'
)parameterLimit
The maximum number of URL-encoded parameters (default: 1000
)busboyLimits
The multipart limits defined by BusboyIf you are using external JSON schemas with $ref
, you can add them to the module before you compile the middleware. Use handler.addJsonSchema(schema, key)
to compile automatically when used.
handler.addJsonSchema()
accepts a third (optional) options
argument. Supported options
are:
ajv
Custom Ajv instance. E.g. handler.addJsonSchema(schema, key, {ajv: myAjvInstance})
. The provided ajv instance can later be passed as an option to the handler to perform validation.The library intercepts incoming requests and does validation. It will respond with 400
, 406
or 415
error instances from http-errors. Validation errors are attached to 400
instances and noted using ramlValidation = true
and requestErrors = []
(an array of errors that were found, compatible with request-error-handler).
See the code for a complete list of errors formats.
Please note: XML validation does not have a way to get the keyword
, dataPath
, data
or schema
. Instead, it has a meta
object that contains information from libxmljs
(domain
, code
, level
, column
, line
).
To render the error messages for your application, look into error handling for Express, Connect, Router or any other middleware error handler. If you want a pre-built error handler, try using request-error-handler, which provides a pre-defined error formatter.
MIT license
FAQs
Middleware for validating requests and responses based on a RAML method object
The npm package osprey-method-handler receives a total of 943 weekly downloads. As such, osprey-method-handler popularity was classified as not popular.
We found that osprey-method-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.