Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
request-pre
Advanced tools
Readme
format data before request send
// services/index.js
import Service from 'request-pre';
import apiSchemaList from './apis';
if (process.env.NODE_ENV === 'development') {
const mocks = require('./mocks');
Object.keys(mocks).forEach((methodName) => {
if (apiSchemaList[methodName]) {
apiSchemaList[methodName].mock = mocks[methodName];
}
});
}
const serviceConfig = {
prefix: '/domain',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
config: {
custom: 'option',
},
};
const service = new Service(apiSchemaList, serviceConfig, function ({config, url, mock}) {
// requester
const { path, query, body, method, headers } = url;
return Promise.resolve({
config,
mock,
...url,
});
});
service.list = function(...args) {
return service.$list(...args).then((data) => {
console.log('rewrite list');
return data;
});
};
// not do this
// service.$list = function(...args) {
// return Promise.reject('');
// }; will throw error
// services/apis.js
export default {
list: {
url: {
path: '/a/b/{id}',
method: methods.GET,
query: {
search: 1,
},
headers: {
'x-option': 'custom',
},
},
},
detail: {
url: {
path: '/a/b/{id}', // support path param
method: methods.POST,
query: {
search: 1,
},
body: {
name: 'test',
},
headers: {
'x-option': 'custom',
},
},
},
};
// services/mocks.js
export default {
list: {
mock: {
'list.success': {
success: true,
data: [], // or () => [],
},
},
},
};
// case
import service from '../services';
services.list({
path: {
id: 2,
},
query: {
status: 4,
},
body: {
xx: 2,
},
headers: {
'x-option': 'custom',
'Content-Type': 'application/x-www-form-urlencoded'
},
config: {
mock: 'list.success',
},
});
// before send data
{
"config": {
"custom": "option",
"mock": "list.success"
},
"mock": {
"mock": {
"list.success": {
"success": true,
"data": []
}
}
},
"url": {
"path": "/domain/a/b/2",
"method": "GET",
"query": {
"search": 1,
"status": 4
},
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"x-option": "custom"
}
}
}
FAQs
process format data before request send
We found that request-pre 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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).