Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
config-req
Advanced tools
Axios wrapper based on a config file
This modules gives you some axios request methods based on a config so that you don't need to worry about method and URL and how to handle their changes on each environments.
npm install config-req
const request = require('config-req');
// Your env configuration
const config = {
activateAccount: {
url: 'http://localhost:5000/v1/account/activate',
method: 'post',
},
};
const api = request(config);
console.log(api); // returns an object like this { activateAccount: <Promise> }
// Api instance contains a request with the method and URL already configured
api.activateAccount()
.then(response => {
console.log(response); // Axios response
});
const request = require('config-req');
// Your env configuration with nested objects
const nestedOptions = {
registration: {
activateAccount: {
url: 'http://localhost:5000/v1/account/activate',
method: 'post',
},
},
};
const api = request(nestedOptions);
console.log(api); // returns an object like this { registration: { activateAccount: <Promise> } }
// Api instance contains a request with the method and URL already configured
api.registration.activateAccount()
.then(response => {
console.log(response); // Axios response
});
const request = require('config-req');
const options = {
advanced: {
withBodyInfo: {
url: 'http://localhost:5000/v1/account/activate',
method: 'post',
},
withURLParams: {
url: 'http://localhost:5000/v1/account/:id/activate',
method: 'get',
},
},
};
const api = request(options);
api.advanced.withBodyInfo({
body: { example: 'example' }, // this is how to send body params
params: { example: 'example' }, // this is how to send query params
headers: { Authorization: 'Bearer example' }, // this is how to send header params
})
.then(response => {
console.log(response); // Axios response
});
// This is when we want to handle dynamic url params like this
// http://localhost:5000/v1/account/:id/activate
// To change that ID we need to setup the urlParams
api.advanced.withURLParams({
body: { example: 'example' }, // this is how to send body params
params: { example: 'example' }, // this is how to send query params
headers: { Authorization: 'Bearer example' }, // this is how to send header params
urlParams: { id: 'urlParam' },
})
.then(response => {
console.log(response); // Axios response
});
You can send a complete req object like the one express.js uses. Note for now, it needs to be extended with a flag for version 1.1.0. For version 2.0.0 this will not be needed.
const request = require('config-req');
const options = {
withURLParams: {
url: 'http://localhost:5000/v1/account/:id/activate',
method: 'get',
},
};
const api = request(options);
const reqObject = {
body: { example: 'example' }, // this is how to send body params
params: { example: 'example' }, // this is how to send query params
headers: { Authorization: 'Bearer example' }, // this is how to send header params
};
// V1 version
api.withURLParams({
...reqObject,
fullRequest: true,
})
.then(response => {
console.log(response); // Axios response
});
// V2 version
api.withURLParams(reqObject)
.then(response => {
console.log(response); // Axios response
});
This fullRequest: true
needs to be added to support in V1 a mix of query params and URL params from a req Object request with the old behaviour.
If you want to change it from V2 you must change this cases:
// if you mix params and urlParams in V2 it won't work as expected
{
params: { example: 'example' },
urlParams: { id: 'urlParam' },
body: { example: 'this is an example' }
}
// just remove it from your code to work with V2
{
params: { example: 'example' },
urlParams: { id: 'urlParam' }
}
To contribute you must send a PR. This is how you can run the project as a developer.
Install dependencies
npm install
Execute tests
npm run test
FAQs
Axios wrapper based on a config file
We found that config-req demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.