
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
@amidoltd/shared-req-res-handler
Advanced tools
web response/request model classes for router's in express like framework
Can be used with any web framework like express, should be used to strip out any meta data in the request object, allowing for quick access to headers, body, params, query objects
npm i @amidoltd/shared-req-res-handler
var RestModel = require('@amidoltd/shared-req-res-handler');
var SomeFoo = require('./someFoo');
/**
* sample PUT request
*/
router.post('/:mandatoryPathParam/:optionalPathParam?', function (req, res) {
this._req = req;
// fullObject will parse the entire request and strip out all properties except body, headers, params, query
var someFoo = new SomeFoo(RestModel.Reqst.fullObject(this._req));
someFoo.methodRequiringFullRequestObject((e, d) => {
if (e) {
res.statusCode = 500;
res.send(RestModel.Resp.errorResp(e, "ANSIBLE160x5")); // TODO stringify error response on app side
res.end();
} else {
res.statusCode = 200;
res.send(RestModel.Resp.successResp(d));
res.end();
}
});
});
var RestModel = require('@amidoltd/shared-req-res-handler');
var SomeFoo = require('./someFoo');
/**
* sample PUT request
*/
router.put('/:mandatoryPathParam/:optionalPathParam?', function (req, res) {
this._req = req;
// params will parse the params of request and strip out all other properties
var someFoo = new SomeFoo(RestModel.Reqst.fullObject(this._req));
someFoo.methodRequiringParamsOfTheRequestOnly((e, d) => {
if (e) {
res.statusCode = 500;
res.send(RestModel.Resp.errorResp(e, "ANSIBLE160x5")); // TODO stringify error response on app side
res.end();
} else {
res.statusCode = 200;
res.send(RestModel.Resp.successResp(d));
res.end();
}
});
});
var RestModel = require('@amidoltd/shared-req-res-handler');
var requestParsed = RestModel.Reqst.fullObject(this._req);
console.log(requestParsed);
{
body: {},
params: {},
headers: {},
query: {}
}
This will create a unified response Model to be consumed in client apps
{
responseData: {}
}
{
responseData: [{}]
}
{
responseData: ""
}
{
responseData: {},
code: ""
}
FAQs
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
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.