
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
@single9/api-wrapper
Advanced tools
Define and Call your restful APIs like a function.
This package is based on @single9/api-tester
but use Axios instead of Request.
npm i @single9/api-wrapper
const ApiWrapper = require('@single9/api-wrapper');
const api = new ApiWrapper([
{
name: '<Api Name>', // only allow certain words and digits
path: '<Api Path>', // e.g. /api/posts
method: '<HTTP Method>', // e.g. post or POST
},
], {
configureAxios(axios){
// The axios you can add interceptors or global functions.
},
baseUrl: '<Base URL of API>', // e.g. https://jsonplaceholder.typicode.com
// Default: http://localhost:3000
headers: {
// The headers you want to send. e.g. 'authorization': 'Bearer SAdoweasd...',
},
auth: { // authorization
username: 'username',
password: 'password',
}
})
baseUrl
You can use factory function to dynamically set the base URL. This is useful if your host domain is a SRV record.
Example
const api = new ApiWrapper([
{
name: '<Api Name>', // only allow certain words and digits
path: '<Api Path>', // e.g. /api/posts
method: '<HTTP Method>', // e.g. post or POST
},
], {
baseUrl: async () => resolveSRV(process.env.API_HOST),
});
api.<api_name>(params)
ApiWrapper
instance.Used for query string. e.g. /users?limit=100
api.test({
queryString: {
key: value
}
})
api.test({
queryString: [
{
name: string,
value: string | number,
}
]
})
Used for path parameters. e.g. /user/:id
api.test({
pathParams: {
key: value
}
})
api.test({
pathParams: [
{
name: string,
value: string | number,
}
]
})
const ApiWrapper = require('@single9/api-wrapper');
// Create your API schema
const schema = [
{
name: 'newPost', // this is your api function name
path: '/posts',
method: 'post',
},
{
name: 'getTodo',
path: '/todos/:todoId', // path parameter
method: 'get',
},
];
const api = new ApiWrapper(schema, {
configureAxios(item){
item.interceptors.request.use(
(request) => { console.log('url: %s , req: %o', request.url); return request; },
)
item.interceptors.response.use(
(response) => { console.log('url: %s , res: %o', response.url, response.data); return response; },
)
},
baseUrl: 'https://jsonplaceholder.typicode.com',
});
async function start() {
try {
const post = await api.newPost({
// Post Body
data: {
title: 'foo!!!!!!',
body: 'bar!!',
userId: 1
},
});
console.log(post.data);
const get = await api.getTodo({
pathParams: {
todoId: 2, // replace `:todoId` with value 2.
},
});
console.log(get.data);
} catch (err) {
console.error(err);
}
}
start();
FAQs
Define and Call your restful APIs like a function.
The npm package @single9/api-wrapper receives a total of 110 weekly downloads. As such, @single9/api-wrapper popularity was classified as not popular.
We found that @single9/api-wrapper demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.