Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
express-endpoint
Advanced tools
A tool to create and document RESTful api endpoints in a declaritive way.
npm install express-endpoint
or
git clone http://github.com/dokipen/express-endpoint.git
cd express-endpoint
npm link
The develop script runs the tests and app in a loop, restarting the loop each time a source file is changed. You'll need inotifywait to use develop.sh. On gentoo and debian/ubuntu it is provided by the inotify-tools package.
$ npm run-script develop
http://express-endpoint.herokuapp.com/
Endpoints can be defined using the module function. It takes a single options parameter that is an object containing the following options.
Once the Endpoint
is created, it can be mounted on the express app by calling
endpoint.mount(app)
. mount(app)
is a convenience method. You can also set
things up manually like so:
app.get(endpoint.config.path, endpoint.middleware(), endpoint.config.handler);
endpoint.middleware(selected)
returns an Array
of middleware for the
Endpoint
. This included the render
and params
middleware by default.
The render
middleware adds a endpoint.render(payload)
function to the
res
object. The function will render an Object
in the appropriate
format according to the Accept
header.
The params
middleware is the meat of Endpoint
. It is where the parameters
and rules are used to parse the request. It adds an endpoint.params
field to
the req
object that contains the parsed parameters.
Catalog is used to render the documentation for all Endpoint
s. It is called
via the module property function catalog(opts)
. It takes a single options
parameter that is an object containing the following properties.
In addition to the Endpoint
middleware, there are two general middlewares.
This handler will render any parsing/validation errors for request
parameters, according to the Accept
header.
var errorHandler = require('express-endpoint').middleware.errorHandler;
app.use(errorHandler());
note This would be better if it were part of the Endpoint middleware, but the current version of express doesn't support URL specifice errorHandler middleware.
This handler provides the default express-endpoint
static content.
var static = require('express-endpoint').middleware.static;
app.use(static());
Parameters are defined as an object with the following parameters.
String
rules for the parameter.Rules are specified as strings, with a single optional parameter. The rule name must match an existing default rule or a custom rule that you defined. If the rule takes a parameter, it should be appended to the end of the rule between parenthesis. To define a default rule, the rules would be as follows:
['default(mydefaultvalue)']
For rules that don't take parameters, the parenthesis can be omitted.
['once']
Rules are executed in the order specified. Builtin rules are described below.
express-endpoint
validates and sanitizes parameters via rules.
express-endpoint
comes with a set of builtin rules, and custom rules are
easily added. To add rules, set the 'rules' Endpoint
options. The default
rules can still be used as long as you don't use the same rule name with your
custom rules. Using the same name as a default rule will override that rule
with your implementation. All rules accept an Array
of values as input, but
can return a single value. Make sure that any rules that return a single value
are specified last.
A rule is defined as a function(parameterName, stringArgument)
that returns
a validator/sanitizer function(arrayOfParameterValues). It should throw an
Error for invalid values, or return a sanitized Array
of values for valid
values.
Here is an example of defining a custom rule to make sure a value is greater than or equal to 18. It assumes that the parameter has already been processed by the 'number' rule.
{ path: '/my/endpoint'
.. [snip] ..
, rules:
{ gte18: function(name, arg) {
return function(vals) {
return vals.map(function(val) {
if (val < 18) {
throw new Error('['+val+'] is less then 18')
}
})
}
}
}
}
You can also look at lib/rules.js for more examples.
To customize the CSS, mount your CSS somewhere in the app, then pass the URIs
to your custom CSS to the endpoint and catalog objects via the stylesheets
option. ex.
var express = require('express')
, app = express()
, express_endpoint = require('express-endpoint')
, Endpoint = express_endpoint.Endpoint
, catalog = express_endpoint.catalog;
app.use(static('public'));
app.use(express_endpoint.middleware.errorHandler());
var endpoint = new Endpoint({
stylesheets: ['public/my/styles.css'],
[snip]
});
endpoint.mount(app);
catalog = catalog({
stylesheets: ['public/my/styles.css'],
endpoints: [endpoint]
});
app.get('/docs', catalog);
app.listen(3000);
You can override the views similarly with the view
and render_view
options.
new Endpoint({
view: __dirname + '/myviews/doc.jade',
render_view: __dirname + '/myviews/render.jade'
})
catalog({
view: __dirname + '/myviews/doc.jade',
})
FAQs
Parse, validate, document and modify endpoint parameters.
The npm package express-endpoint receives a total of 0 weekly downloads. As such, express-endpoint popularity was classified as not popular.
We found that express-endpoint demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.