Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
This is a module for building HTTP API clients.
Initialize a new client.
Options
_log
callsUsage
var papi = require('papi');
var client = new papi.Client({
baseUrl: 'https://api.github.com',
headers: { 'user-agent': 'PapiGitHub/0.1.0' },
timeout: 5 * 1000,
});
Make an HTTP request.
Arguments
ctx.err
or ctx.res
. Call next
without arguments to continue execution, next(err)
to break with an error, or next(false, arguments...)
to trigger the final callback with the given arguments.Request
/user/{id}
)_log
callsThere are also _get
, _head
, _post
, _put
, _delete
, _patch
, and
_options
shortcuts with the same method signature as _request
.
Usage
var opts = {
path: '/users/{username}/gists',
params: { username: 'silas' },
};
client._get(opts, function(err, res) {
if (err) {
console.log('error', err.message);
}
if (res) {
console.log('statusCode', res.statusCode);
console.log('body', res.body);
}
});
Result
statusCode 200
body [ { url: 'https://api.github.com/gists/9458207',
...
Emit log events.
Arguments
Usage
client.on('log', function(tags) {
console.log({
tags: tags,
data: Array.prototype.slice.call(arguments, 1),
});
});;
client._log(['debug', 'github', 'gist'], 'silas');
Result
{ data: [ 'silas' ], tags: [ 'debug', 'github', 'gist' ] }
Register an extension function.
Arguments
Usage
client._ext('onRequest', function(ctx, next) {
console.log('request', ctx.opts.method + ' ' + ctx.opts.path);
ctx.start = new Date();
next();
});
client._ext('onResponse', function(ctx, next) {
var duration = new Date() - ctx.start;
var statusCode = ctx.res ? ctx.res.statusCode : 'none';
console.log('response', ctx.opts.method, ctx.opts.path, statusCode, duration + 'ms');
next();
});
Result
request GET /users/{username}/gists
response GET /users/{username}/gists 200 1141ms
Register a plugin.
Arguments
Usage
client._plugin(require('papi-retry'));
/**
* Module dependencies.
*/
var papi = require('papi');
var util = require('util');
/**
* GitHub API client
*/
function GitHub(opts) {
opts = opts || {};
if (!opts.baseUrl) {
opts.baseUrl = 'https://api.github.com';
}
if (!opts.headers) {
opts.headers = {};
}
if (!opts.headers.accept) {
opts.headers.accept = 'application/vnd.github.v3+json';
}
if (!opts.headers['user-agent']) {
opts.headers['user-agent'] = 'PapiGitHub/0.1.0';
}
if (opts.tags) {
opts.tags = ['github'].concat(opts.tags);
} else {
opts.tags = ['github'];
}
if (!opts.timeout) {
opts.timeout = 60 * 1000;
}
papi.Client.call(this, opts);
if (opts.debug) {
this.on('log', console.log);
}
}
util.inherits(GitHub, papi.Client);
/**
* Get user gists
*/
GitHub.prototype.gists = function(username, callback) {
var opts = {
path: '/users/{username}/gists',
params: { username: username },
};
return this._get(opts, callback);
};
/**
* Print gists for user `silas`
*/
function main() {
var github = new GitHub({ debug: true });
github.gists('silas', function(err, res) {
if (err) throw err;
console.log('----');
res.body.forEach(function(gist) {
if (gist.description) console.log(gist.description);
});
});
}
/**
* Initialize
*/
if (require.main === module) {
main();
} else {
module.exports = GitHub;
}
This work is licensed under the MIT License (see the LICENSE file).
FAQs
Build HTTP API clients
We found that papi 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.