Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unirest

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unirest - npm Package Compare versions

Comparing version 0.3.6 to 0.3.7

15

index.js

@@ -207,3 +207,3 @@ /**

/**
* Append query string to request uri.
* Serialize value as querystring representation, and append or set on `Request.options.url`
*

@@ -234,9 +234,8 @@ * @param {String|Object} value

/**
* Set body and do some pre-sending transformations...
* Data marshalling for HTTP request body data
*
* Determines type whether `form` or `json`.
* For other types use `.type()` to set the _content-type_.
* Determines whether type is `form` or `json`.
* For irregular mime-types the `.type()` method is used to infer the `content-type` header.
*
* If type is _application/x-www-form-urlencoded_ data will be appended to the
* previously set body data.
* When mime-type is `application/x-www-form-urlencoded` data is appended rather than overwritten.
*

@@ -333,4 +332,4 @@ * @param {Mixed} data

/**
* Finalize and send the request, after a response has been recieved do some additional post-processing
* that request fails to do (this section mimics superagent style response).
* Sends HTTP Request and awaits Response finalization. Request compression and Response decompression occurs here.
* Upon HTTP Response post-processing occurs and invokes `callback` with a single argument, the `[Response](#response)` object.
*

@@ -337,0 +336,0 @@ * @param {Function} callback

{
"name": "unirest",
"version": "0.3.6",
"version": "0.3.7",
"description": "Simple HTTP Request client.",

@@ -12,3 +12,3 @@ "main": "index.js",

"mime": "~1.2.11",
"request": "~2.47.0"
"request": "~2.51.0"
},

@@ -15,0 +15,0 @@ "devDependencies": {

@@ -27,3 +27,3 @@ # Unirest for Node.js [![Build Status](http://img.shields.io/travis/Mashape/unirest-nodejs/master.svg)](https://travis-ci.org/Mashape/unirest-nodejs) [![NPM Version](http://img.shields.io/npm/v/unirest.svg)](https://www.npmjs.com/package/unirest)

unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.header('Accept': 'application/json')
.send({ "parameter": 23, "foo": "bar" })

@@ -41,3 +41,3 @@ .end(function (response) {

unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.headers('Accept': 'application/json')
.field('parameter', 'value') // Form field

@@ -54,3 +54,3 @@ .attach('file', '/tmp/file') // Attachment

unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.headers('Accept': 'application/json')
.send(new Buffer([1,2,3]))

@@ -69,7 +69,6 @@ .end(function (response) {

- `method` - Request type (GET, PUT, POST, etc...)
- `uri` - _Optional_; When declared the method will return a [Request](#request) object.
Otherwise it will return the method below with `method` set to the method given.
- `headers` (`Object`) - _Optional_; Will be aliased to unirest\[method] `headers` argument when `uri` is present.
- `body` (`Mixed`) - _Optional_; Will be aliased to unirest\[method] `body` argument when `uri` is present.
- `callback` (`Function`) - _Optional_; Will be aliased to unirest\[method] `callback` argument when `uri` is present.
- `uri` - _Optional_; When passed will return a [Request](#request) object. Otherwise returns generated function with `method` pre-defined (e.g. `unirest.get`)
- `headers` (`Object`) - _Optional_; HTTP Request headers
- `body` (`Mixed`) - _Optional_; HTTP Request body
- `callback` (`Function`) - _Optional_; Invoked when Request has finalized with the argument [Response](#response)

@@ -80,3 +79,3 @@ ## unirest\[method](url [, headers, body, callback])

- `url` - Request location.
- `headers` (`Object` | `Function`) - _Optional_; When `Object` headers are passed along to the `Request.set()` method,
- `headers` (`Object` | `Function`) - _Optional_; When `Object` headers are passed along to the [`Request.header`](#requestheaderobject-or-field-value) method,
when `Function` this argument is used as the `callback`.

@@ -143,3 +142,3 @@ - `body` (`Mixed` | `Function`) - _Optional_; When `body` is not a `Function` it will be passed along to `Request.send()` method,

`mikeal/request` library (the underlying layer of unirest-nodejs) for direct use.
`mikeal/request` library (the underlying layer of unirest) for direct use.

@@ -157,5 +156,3 @@ # Request

Request.headers({
'Accepts': 'application/json'
}).end(function (response) {
Request.header('Accepts': 'application/json').end(function (response) {
...

@@ -206,3 +203,3 @@ });

```js
Request.set({
Request.headers({
'Accepts': 'application/json',

@@ -213,6 +210,8 @@ 'User-Agent': 'Unirest Node.js'

Note the usage of [`Request.headers`](#requestheaders) which is simply an alias to the `Request.header` method, you can also use [`Request.set`](#requestset) to set headers.
**Arguments**
```js
Request.set('Accepts', 'application/json');
Request.header('Accepts', 'application/json');
```

@@ -240,4 +239,6 @@

When `Object` is passed value is processed as a `querystring` representation, otherwise we directly use the `String` passed and append it to `Request.options.url`. If `Request.options.url` has a trailing `?` already, we append it with `& + value` otherwise we append as `? + value`
Serializes argument passed to a querystring representation.
Should `url` already contain a querystring, the representation will be appended to the `url`.
```js

@@ -256,6 +257,9 @@ unirest.post('http://httpbin.org/get')

Ease of use method for setting the body without having to worry about processing the data for popular formats such as `JSON`, `Form Encoded`, otherwise the `body` is set on `Request.options` as the given value.
Data marshalling for HTTP request body data
By default sending strings with no `Content-Type` preset will set `Content-Type` to `application/x-www-form-urlencoded`, and multiple calls will be concatenated with `&`. Otherwise multiple calls will be appended to the previous `body` value.
Determines whether data mime-type is `form` or `json`.
For irregular mime-types the `.type()` method is used to infer the `content-type` header.
When mime-type is `application/x-www-form-urlencoded` data is appended rather than overwritten.
**JSON**

@@ -303,3 +307,3 @@

Uses `Request.header()` to set header value.
Uses [`Request.header`](#requestheaderobject-or-field-value) to set header value.

@@ -328,3 +332,3 @@ ```js

unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.header('Accept': 'application/json')
.field({

@@ -347,3 +351,3 @@ 'parameter': 'value'

unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.header('Accept': 'application/json')
.field('parameter', 'value') // Form field

@@ -621,2 +625,13 @@ .attach('file', 'dog.png') // Attachment

#### Request.end(Function callback)
Sends HTTP Request and awaits Response finalization. Request compression and Response decompression occurs here.
Upon HTTP Response post-processing occurs and invokes `callback` with a single argument, the `[Response](#response)` object.
```js
unirest.get('http://httpbin.org/get').end(function (response) {
...
});
```
## Request Aliases

@@ -626,39 +641,39 @@

**Alias** for `Request.header()`
**Alias** for [`Request.header()`](#requestheaderobject-or-field-value)
#### Request.headers
**Alias** for `Request.header()`
**Alias** for [`Request.header()`](#requestheaderobject-or-field-value)
#### Request.redirects
**Alias** for `Request.maxRedirects()`
**Alias** for [`Request.maxRedirects()`](#requestmaxredirectsnumber)
#### Request.redirect
**Alias** for `Request.followRedirect()`
**Alias** for [`Request.followRedirect()`](#requestfollowredirectboolean)
#### Request.ssl
**Alias** for `Request.strictSSL()`
**Alias** for [`Request.strictSSL()`](#requeststrictsslboolean)
#### Request.ip
**Alias** for `Request.localAddress()`
**Alias** for [`Request.localAddress()`](#requestlocaladdressstring)
#### Request.complete
**Alias** for `Request.end()`
**Alias** for [`Request.end()`](#requestlocaladdressstring)
#### Request.as.json
**Alias** for `Request.end()`
**Alias** for [`Request.end()`](#requestendfunction-callback)
#### Request.as.binary
**Alias** for `Request.end()`
**Alias** for [`Request.end()`](#requestendfunction-callback)
#### Request.as.string
**Alias** for `Request.end()`
**Alias** for [`Request.end()`](#requestendfunction-callback)

@@ -665,0 +680,0 @@ # Response

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc