
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Abstraction for standard API responses based on this post by Andrey Petrov
{
"code": 200,
"status": "ok",
"messages": [],
"result": {
"user": {
"id": 123,
"name": "shazow"
}
}
}
Install
$ npm install ayeepi --save
Usage
const ayeepi = require('ayeepi');
// ... some restify setup or whatever
app.post('/foo', (req, res) => {
const id = req.body.id;
let message;
doSomething(id)
.then((data) => {
message = `It worked for ${id}!`;
ayeepi.ok(res, message);
})
.catch((err) => {
log.error(err.message);
message = `An error occures while doing that thing for ${id}`;
ayeepi.error(res, message);
})
})
/**
* Sends a 200 `OK` response
*
* @param {Response} A response object
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 200,
* "status": "OK",
* "messages": [`Whatever you did worked`]
* }
*
*/
ok(res, messages)
/**
* Sends a 500 `Internal Server Error` response
*
* @param {Response} A response object
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer. Error
* message(s) should go here
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 500,
* "status": "Internal Server Error",
* "messages": [`something broke!`]
* }
*
*/
error(res, messages)
/**
* Sends a 403 `Forbidden` response
*
* @param {Response} A response object
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 403,
* "status": "Forbidden",
* "messages": [`can't touch this!`]
* }
*
*/
forbidden(res, messages)
/**
* Sends a 404 `Not Found` response
*
* @param {Response} A response object
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 404,
* "status": "Not Found",
* "messages": [`couldn't find it`]
* }
*
*/
notFound(res, messages)
/**
* Sends a 501 `Not Implemented` response
*
* @param {Response} A response object
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 501,
* "status": "Not Implemented",
* "messages": [`this isn't ready!`]
* }
*
*/
notImplemented(res, msgs)
/**
* Sends a 401 `Unauthorized` response
*
* @param {Response} A response object
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 403,
* "status": "Unauthorized",
* "messages": [`I don't know you!`]
* }
*
*/
unauthorized(res, msgs)
/**
* Sends a 200 `OK` response with a data payload
*
* @param {Response} A response object
* @param {Object} The data to be sent to the client
* @param {Array|String} A string or array of strings to be used to
* transport messages to the API consumer
* @return {Object} The payload that was sent to the client
*
* @example
* {
* "code": 200,
* "status": "OK",
* "messages": [`Here's the result of the stuff`],
* "result": {} // your data
* }
*
*/
send(res, data, msgs)
Tests
$ npm test
Totally welcome. Create a PR, create a passing test, adhere to .jshint rules and if it makes sense - I'm happy to merge it!
FAQs
- Abstraction for standard API responses
The npm package ayeepi receives a total of 14 weekly downloads. As such, ayeepi popularity was classified as not popular.
We found that ayeepi 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.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.