Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
native-request
Advanced tools
Readme
Native Request is a simple module that makes you create native node.js requests supports https.
Installation
Usage
Planned features
Install the dependencies and devDependencies and start the server.
npm install native-request
Easy
let request = require('native-request');
request.request({
url: "http://github.com/",
method: 'POST',
}, function(err, data, status, headers) {
console.log(status); //200
console.log(data); // page content
console.log(headers); // response headers
});
Full
let request = require('native-request');
request.request({
url: "http://github.com/",
method: 'POST',
Cookies: { john: "doe", human: true },
headers: {
authorization: "Token121"
},
requestOptions: {
followRedirect: false,
maxRedirect: 1,
trustRedirect: false
}
}, function(err, data, status, headers) {
console.log(status); //200
console.log(data); // page content
console.log(headers); // response headers
});
Options | Required | Type | Parameters | Default |
---|---|---|---|---|
url | ✓ | String | Target url | |
method | ✓ | String | HTTP method to use. More info here | |
Headers | JSON Object | Pass headers to the request with a JSON format. | {"content-type": "application/json"} | |
Cookies | JSON Object | Pass cookies to the request with a JSON format | ||
requestOptions | See below |
The parameters below are here for client configuration. None of these parameters will be sent. These parameters must be put in the object 'requestOptions'
Options | Required | Type | Parameters | Default |
---|---|---|---|---|
followRedirect | boolean | Decide if we should follow the redirects | true | |
maxRedirect | int | Decide the maximum number of redirects allowed | 3 | |
trustRedirect | boolean | If false, headers will not be sent when a redirect happen | true |
let request = require('native-request');
request.get('https://github.com', function(err, data, status, headers) {
if (err) {
throw err;
}
console.log(status); //200
console.log(data); // page content
console.log(headers); // response headers
});
To add custom headers just do like this:
let request = require('native-request');
let headers = {
"content-type": "plain/text"
}
request.get('https://github.com', headers, function(err, data, status, headers) {
if (err) {
throw err;
}
console.log(status); //200
console.log(data); // page content
console.log(headers); // response headers
});
request.post(path, callback)
request.post(path, data, callback)
request.post(path, data, headers, callback)
To send an empty post:
let request = require('native-request');
request.post('https://github.com', function(err, data, status, headers) {
if (err) {
throw err;
}
console.log(status); //200
console.log(data); // page content
console.log(headers); // response headers
});
With headers and data:
let request = require('native-request');
let data = {
"example": true,
}
let headers = {
"content-type": "plain/text"
}
request.post('https://github.com', data, headers, function(err, data, status, headers) {
if (err) {
throw err;
}
console.log(status); //200
console.log(data); // page content
console.log(headers); // response headers
});
MIT. Copyright (c) Samuel Marchese.
FAQs
A simple package with no dependencies for native requests using callback
The npm package native-request receives a total of 605,194 weekly downloads. As such, native-request popularity was classified as popular.
We found that native-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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.