EndPoint is a schema-validated waterfall.
var EndPoint = require('api-endpoint'),
Joi = EndPoint.Joi;
var myEndpoint = EndPoint.create({
headers: Joi.object(), // Headers validator
payload: Joi.object(), // Payload validator
query: Joi.object(), // Query string validator
params: Joi.object(), // URL string validator
response: Joi.object(), // Response validator
validateOptions: { // optional JOI validation options
abortEarly: false,
stripUnknown: true
},
filters: [ // An array of work to perform
function findUser(data, next) {
next(err || null, data);
},
function createTask(data, next) {
next(err || null, data);
}
]
});
module.exports = endpoint;
myEndpoint.run(data, function(err, data) {
console.log(err, data); // `data` is the final object scoped to the outgoing schema
})
Your endpoint is a waterfall. If any of your filters
error, your endpoint will run its callback function with the error you provide (data
will be null
).