
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
api_request
Advanced tools
Simple library for defining API requests asynchronously. Creates readable requests using a fuild chainable interface. Detects the content type and decodes it accordingy (currently available for application/json and application/x-www-form-urlencoded). Also, if one specifies the content type, a JS object may be passed in and it will be converted to the proper format by the proper content encoder.
At your command prompt type:
npm install api_request
Just include the library and start building requests:
var api_request = require('api_request');
var r = new api_request('http', 'themarg.in');
r.get('/').on('reply', function(reply, res) {
console.log(reply);
});
Also, you could make a request over SSL with basic authentication:
var r = new api_request('https', 'auth.themarg.in');
r.with_basic_auth('ada', '4d4').
get('/index.php').on('reply', function(reply, res) {
console.log(reply.greeting);
});
Or, you could post a JSON object over HTTPS with basic authentication:
var r = new api_request('https', 'auth.themarg.in');
r.with_content_type('application/json').
with_basic_auth('ada', '4d4').
with_payload({'greeting': 'hi'}).
post('/index.php').on('reply', function(reply, res) {
console.log(reply.greeting);
});
Currently the only supported protocols are http or https. If someone wrote a module for another protocol that could be used as well, since it loads the module via a require statement.
It supports the four basic http verbs: 'GET', 'POST'. 'PUT', 'DELETE'.
Headers can be set like so:
var r = new api_request('http', 'themarg.in');
r.add_headers({'X-Orginating-IP': '192.168.5.3'}).
get('/index.php').on('reply', function(reply, res) {
console.log(reply);
});
Multiple headers can be set at once.
If the API you use this with requests or replies with a different format from x-www-form-urlencoded or json, the library can be extended by providing a content encoder or content handler object. It's quite simple, actually:
var r = new api_request('https', 'auth.themarg.in');
r.add_content_handlers({
'appplication/rss+xml': function(data) {
return decoded_data;
}
});
To send a different encoding, it goes like this:
var r = new api_request('https', 'auth.themarg.in');
r.add_content_encoders({
'appplication/rss+xml': function(data) {
return encoded_data;
}
});
More than one type of encoder or handler can be added at a time.
FAQs
Wrapper for the http client to make beautiful, readable requests.
The npm package api_request receives a total of 2 weekly downloads. As such, api_request popularity was classified as not popular.
We found that api_request 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.