New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lightning-request

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lightning-request - npm Package Compare versions

Comparing version

to
0.0.4

15

index.js

@@ -12,3 +12,2 @@ const http = require('http');

* @param {Any} options.data `data` is the data to be sent as the request body
* @param {String} options.contentType `contentType` is the data to be sent, default: application/json
* @param {Number} options.timeout`timeout` specifies the number of milliseconds before the request times out. If the request takes longer than `timeout`, the request will be aborted.

@@ -39,11 +38,5 @@ * @param {String} options.responseType `responseType` indicates the type of data that the server will respond with, default: json

const timeout = options.timeout || 15000;
const contentType = options.contentType || 'application/json';
if (contentType === 'application/json') {
data = JSON.stringify(data);
} else if (contentType === 'application/x-www-form-urlencoded') {
data = qs.stringify(data);
}
const headers = Object.assign(
{
'Content-Type': contentType,
'Content-Type': 'application/json',
'User-Agent': 'Lightweight Node.js HTTP client',

@@ -53,2 +46,8 @@ },

);
const contentType = headers['Content-Type'];
if (contentType === 'application/json') {
data = JSON.stringify(data);
} else if (contentType === 'application/x-www-form-urlencoded') {
data = qs.stringify(data);
}

@@ -55,0 +54,0 @@ const responseType = options.responseType || 'json';

{
"name": "lightning-request",
"version": "0.0.3",
"version": "0.0.4",
"description": "Lightweight Node.js HTTP client",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -41,2 +41,56 @@ ⚡ Lightweight Node.js HTTP client.

## Request Config
These are the available config options for making requests. Only the url is required. Requests will default to GET if method is not specified.
```
{
// `url` is the server URL that will be used for the request
url: 'http://www.example/test',
// `method` is the request method to be used when making the request
method: 'get', // default
// `headers` are custom headers to be sent
headers: {'X-Requested-With': 'XMLHttpRequest'},
// `data` is the data to be sent as the request body
data: {
firstName: 'Fred'
},
// `timeout` specifies the number of milliseconds before the request times out.
// If the request takes longer than `timeout`, the request will be aborted.
timeout: 1000, // default is `15000` (no timeout)
// `responseType` indicates the type of data that the server will respond with
// options are: 'json', 'text'
responseType: 'json', // default
// `agent` define a custom agent to be used when performing http or https requests,
// respectively, in node.js. This allows options to be added like `keepAlive` that are not enabled by default.
agent: new http.Agent({ keepAlive: true }),
}
```
## Response Schema
The response for a request contains the following information.
```
{
// `statusCode` is the HTTP status code from the server response
statusCode: 200,
// `statusMessage` is the HTTP status message from the server response
statusMessage: 'OK',
// `headers` the headers that the server responded with All header names are lower cased
headers: {},
// `body` is the response data that was provided by the server
body: {}
}
```
## Contributing

@@ -51,1 +105,5 @@

- Open a pull request, and enjoy <3
## License
[MIT](LICENSE)