![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
lengoo-api-response-formatter
Advanced tools
A lib to keep your responses formatted and consistent through your project
A library to keep your responses formatted and consistent through your project.
This library intends to create a consistent response format to be used through your project.
{
data: [...],
error: {},
validations: []
}
{
data: [],
error: {
code: "some-code",
message: "Human message"
},
validations: []
}
{
data: [],
error: {
code: "validation-error",
message: "The request was not processed due to validation issues"
},
validations: [
{
code: "some-code",
message: Human message"',
attribute: "attribute-that-caused-the-error",
value: "given-value-for-attribute"
},
...
]
}
npm install --save lengoo-api-response-formatter
...
module.exports.getById = (req, res) => {
let employee = _.find(employees, { _id: req.swagger.params.id.value });
let response = new Response();
if (employee === undefined) {
response.error = Response.ERRORS.NOT_FOUND;
// You can also especify your own error
// response.error = {
// code: 'not-found',
// message: 'There is no employee to the given ID'
// }
res.status(Response.CODES.NOT_FOUND);
res.json(response.get());
} else {
response.data = employee;
res.json(response.get());
}
};
...
You can add validations in two ways:
...
response.validation = [{
code: "some-validation-code",
message: Human message"',
attribute: "attribute-that-caused-the-error",
value: "given-value-for-attribute"
},
{
code: "another-validation-code",
message: Human message"',
attribute: "attribute-that-caused-the-error",
value: "given-value-for-attribute"
}];
...
Or:
...
response.addValidation = {
code: "another-validation-code",
message: "Human message",
attribute: "attribute-that-caused-the-error",
value: "given-value-for-attribute"
};
...
If you didn't specify an error, the default error for validations will be added to the response.
Coming soon
FAQs
A lib to keep your responses formatted and consistent through your project
The npm package lengoo-api-response-formatter receives a total of 0 weekly downloads. As such, lengoo-api-response-formatter popularity was classified as not popular.
We found that lengoo-api-response-formatter 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.