PHPackages                             rauny-henrique/unirest-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. rauny-henrique/unirest-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

rauny-henrique/unirest-php
==========================

Unirest PHP

v3.0.5(6y ago)0990MITPHPPHP &gt;=5.4.0

Since Feb 19Pushed 4y agoCompare

[ Source](https://github.com/rauny-henrique/unirest-php)[ Packagist](https://packagist.org/packages/rauny-henrique/unirest-php)[ Docs](https://github.com/Mashape/unirest-php)[ RSS](/packages/rauny-henrique-unirest-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (25)Used By (0)

Unirest for PHP [![Build Status](https://camo.githubusercontent.com/0394020364023b66e1d6abb384defe236c91b348d80fcafe531f81ddde360277/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4d6173686170652f756e69726573742d7068702e7376673f7374796c653d666c6174)](https://travis-ci.org/Mashape/unirest-php) [![version](https://camo.githubusercontent.com/2947253c7fa3f3b3ab01cc42fc7a32a40d059b6e3d66b4ca65313bf8ec941d20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4d6173686170652f756e69726573742d7068702e7376673f7374796c653d666c6174)](https://packagist.org/packages/Mashape/unirest-php)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#unirest-for-php--)

[![Downloads](https://camo.githubusercontent.com/1093ced27c8eb53067f84f620aaea0cd078d377fc572a7b04f2b10105ae9b13b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f4d6173686170652f756e69726573742d7068702e7376673f7374796c653d666c6174)](https://packagist.org/packages/Mashape/unirest-php)[![Code Climate](https://camo.githubusercontent.com/85594cb52a637732de23b2571cc845b5c3dffee1e6a711fa08306f8b1ab89f55/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f4d6173686170652f756e69726573742d7068702e7376673f7374796c653d666c6174)](https://codeclimate.com/github/Mashape/unirest-php)[![Coverage Status](https://camo.githubusercontent.com/a97d98ff62cb395ba4885a0f24d9c5770a5132be8d4d02bbabcd575b0b033cf1/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6769746875622f4d6173686170652f756e69726573742d7068702e7376673f7374796c653d666c6174)](https://codeclimate.com/github/Mashape/unirest-php)[![Dependencies](https://camo.githubusercontent.com/9a004fe3cc97f3d814f7ab6c31d26edc79874ddcccb86a02d88a170784b7bf22/68747470733a2f2f696d672e736869656c64732e696f2f76657273696f6e6579652f642f7068702f6d6173686170653a756e69726573742d7068702e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/54b82450050646ca5c0001f3)[![Gitter](https://camo.githubusercontent.com/e2add9a3af65a4b9daf0c69e9aefd349b7f3d6d470655c1040558892565c7db7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4769747465722d4a6f696e253230436861742d626c75652e7376673f7374796c653d666c6174)](https://gitter.im/Mashape/unirest-php)[![License](https://camo.githubusercontent.com/93f623e1f1aeefb6cfcccb9ef72ec741b9559bc0ce8c0d3a74342aba5ff2bdea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f4d6173686170652f756e69726573742d7068702e7376673f7374796c653d666c6174)](https://github.com/Mashape/unirest-php/blob/master/LICENSE)

[![](https://camo.githubusercontent.com/e09513e2159b788d61cb74b6a2b352843d13a61e36afb9a69e8cc6bf450285b9/687474703a2f2f636c2e6c792f696d6167652f32503337335930393073324f2f496d616765253230323031352d31302d31322532306174253230392e34382e3036253230504d2e706e67)](https://camo.githubusercontent.com/e09513e2159b788d61cb74b6a2b352843d13a61e36afb9a69e8cc6bf450285b9/687474703a2f2f636c2e6c792f696d6167652f32503337335930393073324f2f496d616765253230323031352d31302d31322532306174253230392e34382e3036253230504d2e706e67)

[Unirest](http://unirest.io) is a set of lightweight HTTP libraries available in multiple languages, built and maintained by [Mashape](https://github.com/Mashape), who also maintain the open-source API Gateway [Kong](https://github.com/Mashape/kong).

Features
--------

[](#features)

- Utility methods to call `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `CONNECT`, `OPTIONS`, `TRACE`, `PATCH` requests
- Supports form parameters, file uploads and custom body entities
- Supports gzip
- Supports Basic, Digest, Negotiate, NTLM Authentication natively
- Customizable timeout
- Customizable default headers for every request (DRY)
- Automatic JSON parsing into a native object for JSON responses

Requirements
------------

[](#requirements)

- [cURL](http://php.net/manual/en/book.curl.php)
- PHP 5.4+

Installation
------------

[](#installation)

### Using [Composer](https://getcomposer.org)

[](#using-composer)

To install unirest-php with Composer, just add the following to your `composer.json` file:

```
{
    "require-dev": {
        "rauny-henrique/unirest-php": "3.*"
    }
}
```

or by running the following command:

```
composer require rauny-henrique/unirest-php
```

This will get you the latest version of the reporter and install it. If you do want the master, untagged, version you may use the command below:

```
composer require mashape/php-test-reporter dev-master
```

Composer installs autoloader at `./vendor/autoloader.php`. to include the library in your script, add:

```
require_once 'vendor/autoload.php';
```

If you use Symfony2, autoloader has to be detected automatically.

*You can see this library on [Packagist](https://packagist.org/packages/mashape/unirest-php).*

### Install from source

[](#install-from-source)

Download the PHP library from Github, then include `Unirest.php` in your script:

```
git clone git@github.com:Mashape/unirest-php.git
```

```
require_once '/path/to/unirest-php/src/Unirest.php';
```

Usage
-----

[](#usage)

### Creating a Request

[](#creating-a-request)

So you're probably wondering how using Unirest makes creating requests in PHP easier, let's look at a working example:

```
$headers = array('Accept' => 'application/json');
$query = array('foo' => 'hello', 'bar' => 'world');

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $query);

$response->code;        // HTTP Status code
$response->headers;     // Headers
$response->body;        // Parsed body
$response->raw_body;    // Unparsed body
```

### JSON Requests *(`application/json`)*

[](#json-requests-applicationjson)

A JSON Request can be constructed using the `Unirest\Request\Body::Json` helper:

```
$headers = array('Accept' => 'application/json');
$data = array('name' => 'ahmad', 'company' => 'mashape');

$body = Unirest\Request\Body::json($data);

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
```

**Notes:**

- `Content-Type` headers will be automatically set to `application/json`
- the data variable will be processed through [`json_encode`](http://php.net/manual/en/function.json-encode.php) with default values for arguments.
- an error will be thrown if the [JSON Extension](http://php.net/manual/en/book.json.php) is not available.

### Form Requests *(`application/x-www-form-urlencoded`)*

[](#form-requests-applicationx-www-form-urlencoded)

A typical Form Request can be constructed using the `Unirest\Request\Body::Form` helper:

```
$headers = array('Accept' => 'application/json');
$data = array('name' => 'ahmad', 'company' => 'mashape');

$body = Unirest\Request\Body::form($data);

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
```

**Notes:**

- `Content-Type` headers will be automatically set to `application/x-www-form-urlencoded`
- the final data array will be processed through [`http_build_query`](http://php.net/manual/en/function.http-build-query.php) with default values for arguments.

### Multipart Requests *(`multipart/form-data`)*

[](#multipart-requests-multipartform-data)

A Multipart Request can be constructed using the `Unirest\Request\Body::Multipart` helper:

```
$headers = array('Accept' => 'application/json');
$data = array('name' => 'ahmad', 'company' => 'mashape');

$body = Unirest\Request\Body::multipart($data);

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
```

**Notes:**

- `Content-Type` headers will be automatically set to `multipart/form-data`.
- an auto-generated `--boundary` will be set.

### Multipart File Upload

[](#multipart-file-upload)

simply add an array of files as the second argument to to the `Multipart` helper:

```
$headers = array('Accept' => 'application/json');
$data = array('name' => 'ahmad', 'company' => 'mashape');
$files = array('bio' => '/path/to/bio.txt', 'avatar' => '/path/to/avatar.jpg');

$body = Unirest\Request\Body::multipart($data, $files);

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
```

If you wish to further customize the properties of files uploaded you can do so with the `Unirest\Request\Body::File` helper:

```
$headers = array('Accept' => 'application/json');
$body = array(
    'name' => 'ahmad',
    'company' => 'mashape'
    'bio' => Unirest\Request\Body::file('/path/to/bio.txt', 'text/plain'),
    'avatar' => Unirest\Request\Body::file('/path/to/my_avatar.jpg', 'text/plain', 'avatar.jpg')
);

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
```

**Note**: we did not use the `Unirest\Request\Body::multipart` helper in this example, it is not needed when manually adding files.

### Custom Body

[](#custom-body)

Sending a custom body such rather than using the `Unirest\Request\Body` helpers is also possible, for example, using a [`serialize`](http://php.net/manual/en/function.serialize.php) body string with a custom `Content-Type`:

```
$headers = array('Accept' => 'application/json', 'Content-Type' => 'application/x-php-serialized');
$body = serialize((array('foo' => 'hello', 'bar' => 'world'));

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
```

### Authentication

[](#authentication)

First, if you are using [Mashape](https://www.mashape.com/):

```
// Mashape auth
Unirest\Request::setMashapeKey('');
```

Otherwise, passing a username, password *(optional)*, defaults to Basic Authentication:

```
// basic auth
Unirest\Request::auth('username', 'password');
```

The third parameter, which is a bitmask, will Unirest which HTTP authentication method(s) you want it to use for your proxy authentication.

If more than one bit is set, Unirest *(at PHP's libcurl level)* will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. *For some methods, this will induce an extra network round-trip.*

**Supported Methods**

MethodDescription`CURLAUTH_BASIC`HTTP Basic authentication. This is the default choice`CURLAUTH_DIGEST`HTTP Digest authentication. as defined in [RFC 2617](http://www.ietf.org/rfc/rfc2617.txt)`CURLAUTH_DIGEST_IE`HTTP Digest authentication with an IE flavor. *The IE flavor is simply that libcurl will use a special "quirk" that IE is known to have used before version 7 and that some servers require the client to use.*`CURLAUTH_NEGOTIATE`HTTP Negotiate (SPNEGO) authentication. as defined in [RFC 4559](http://www.ietf.org/rfc/rfc4559.txt)`CURLAUTH_NTLM`HTTP NTLM authentication. A proprietary protocol invented and used by Microsoft.`CURLAUTH_NTLM_WB`NTLM delegating to winbind helper. Authentication is performed by a separate binary application. *see [libcurl docs](http://curl.haxx.se/libcurl/c/CURLOPT_HTTPAUTH.html) for more info*`CURLAUTH_ANY`This is a convenience macro that sets all bits and thus makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure.`CURLAUTH_ANYSAFE`This is a convenience macro that sets all bits except Basic and thus makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure.`CURLAUTH_ONLY`This is a meta symbol. OR this value together with a single specific auth value to force libcurl to probe for un-restricted auth and if not, only that single auth algorithm is acceptable.```
// custom auth method
Unirest\Request::proxyAuth('username', 'password', CURLAUTH_DIGEST);
```

Previous versions of **Unirest** support *Basic Authentication* by providing the `username` and `password` arguments:

```
$response = Unirest\Request::get('http://mockbin.com/request', null, null, 'username', 'password');
```

**This has been deprecated, and will be completely removed in `v.3.0.0` please use the `Unirest\Request::auth()` method instead**

### Cookies

[](#cookies)

Set a cookie string to specify the contents of a cookie header. Multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")

```
Unirest\Request::cookie($cookie)
```

Set a cookie file path for enabling cookie reading and storing cookies across multiple sequence of requests.

```
Unirest\Request::cookieFile($cookieFile)
```

`$cookieFile` must be a correct path with write permission.

### Request Object

[](#request-object)

```
Unirest\Request::get($url, $headers = array(), $parameters = null)
Unirest\Request::post($url, $headers = array(), $body = null)
Unirest\Request::put($url, $headers = array(), $body = null)
Unirest\Request::patch($url, $headers = array(), $body = null)
Unirest\Request::delete($url, $headers = array(), $body = null)
```

- `url` - Endpoint, address, or uri to be acted upon and requested information from.
- `headers` - Request Headers as associative array or object
- `body` - Request Body as associative array or object

You can send a request with any [standard](http://www.iana.org/assignments/http-methods/http-methods.xhtml) or custom HTTP Method:

```
Unirest\Request::send(Unirest\Method::LINK, $url, $headers = array(), $body);

Unirest\Request::send('CHECKOUT', $url, $headers = array(), $body);
```

### Response Object

[](#response-object)

Upon recieving a response Unirest returns the result in the form of an Object, this object should always have the same keys for each language regarding to the response details.

- `code` - HTTP Response Status Code (Example `200`)
- `headers` - HTTP Response Headers
- `body` - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays.
- `raw_body` - Un-parsed response body

### Advanced Configuration

[](#advanced-configuration)

You can set some advanced configuration to tune Unirest-PHP:

#### Custom JSON Decode Flags

[](#custom-json-decode-flags)

Unirest uses PHP's [JSON Extension](http://php.net/manual/en/book.json.php) for automatically decoding JSON responses. sometime you may want to return associative arrays, limit the depth of recursion, or use any of the [customization flags](http://php.net/manual/en/json.constants.php).

To do so, simply set the desired options using the `jsonOpts` request method:

```
Unirest\Request::jsonOpts(true, 512, JSON_NUMERIC_CHECK & JSON_FORCE_OBJECT & JSON_UNESCAPED_SLASHES);
```

#### Timeout

[](#timeout)

You can set a custom timeout value (in **seconds**):

```
Unirest\Request::timeout(5); // 5s timeout
```

#### Proxy

[](#proxy)

Set the proxy to use for the upcoming request.

you can also set the proxy type to be one of `CURLPROXY_HTTP`, `CURLPROXY_HTTP_1_0`, `CURLPROXY_SOCKS4`, `CURLPROXY_SOCKS5`, `CURLPROXY_SOCKS4A`, and `CURLPROXY_SOCKS5_HOSTNAME`.

*check the [cURL docs](http://curl.haxx.se/libcurl/c/CURLOPT_PROXYTYPE.html) for more info*.

```
// quick setup with default port: 1080
Unirest\Request::proxy('10.10.10.1');

// custom port and proxy type
Unirest\Request::proxy('10.10.10.1', 8080, CURLPROXY_HTTP);

// enable tunneling
Unirest\Request::proxy('10.10.10.1', 8080, CURLPROXY_HTTP, true);
```

##### Proxy Authenticaton

[](#proxy-authenticaton)

Passing a username, password *(optional)*, defaults to Basic Authentication:

```
// basic auth
Unirest\Request::proxyAuth('username', 'password');
```

The third parameter, which is a bitmask, will Unirest which HTTP authentication method(s) you want it to use for your proxy authentication.

If more than one bit is set, Unirest *(at PHP's libcurl level)* will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. *For some methods, this will induce an extra network round-trip.*

See [Authentication](#authentication) for more details on methods supported.

```
// basic auth
Unirest\Request::proxyAuth('username', 'password', CURLAUTH_DIGEST);
```

#### Default Request Headers

[](#default-request-headers)

You can set default headers that will be sent on every request:

```
Unirest\Request::defaultHeader('Header1', 'Value1');
Unirest\Request::defaultHeader('Header2', 'Value2');
```

You can set default headers in bulk by passing an array:

```
Unirest\Request::defaultHeaders(array(
    'Header1' => 'Value1',
    'Header2' => 'Value2'
));
```

You can clear the default headers anytime with:

```
Unirest\Request::clearDefaultHeaders();
```

#### Default cURL Options

[](#default-curl-options)

You can set default [cURL options](http://php.net/manual/en/function.curl-setopt.php) that will be sent on every request:

```
Unirest\Request::curlOpt(CURLOPT_COOKIE, 'foo=bar');
```

You can set options bulk by passing an array:

```
Unirest\Request::curlOpts(array(
    CURLOPT_COOKIE => 'foo=bar'
));
```

You can clear the default options anytime with:

```
Unirest\Request::clearCurlOpts();
```

#### SSL validation

[](#ssl-validation)

You can explicitly enable or disable SSL certificate validation when consuming an SSL protected endpoint:

```
Unirest\Request::verifyPeer(false); // Disables SSL cert validation
```

By default is `true`.

#### Utility Methods

[](#utility-methods)

```
// alias for `curl_getinfo`
Unirest\Request::getInfo()

// returns internal cURL handle
Unirest\Request::getCurlHandle()
```

---

Made with ♥ from the [Mashape](https://www.mashape.com/) team

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~95 days

Recently: every ~358 days

Total

24

Last Release

2268d ago

Major Versions

1.2.1 → 2.0.02015-01-15

v2.6.6 → v3.0.02016-02-25

PHP version history (2 changes)1.1PHP &gt;=5.3.0

2.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/99811376?v=4)[raunyhenrique](/maintainers/raunyhenrique)[@raunyhenrique](https://github.com/raunyhenrique)

---

Top Contributors

[![ahmadnassri](https://avatars.githubusercontent.com/u/183195?v=4)](https://github.com/ahmadnassri "ahmadnassri (102 commits)")[![subnetmarco](https://avatars.githubusercontent.com/u/964813?v=4)](https://github.com/subnetmarco "subnetmarco (83 commits)")[![esseguin](https://avatars.githubusercontent.com/u/1429412?v=4)](https://github.com/esseguin "esseguin (12 commits)")[![michelezonca](https://avatars.githubusercontent.com/u/392758?v=4)](https://github.com/michelezonca "michelezonca (6 commits)")[![motdotla](https://avatars.githubusercontent.com/u/3848?v=4)](https://github.com/motdotla "motdotla (5 commits)")[![nijikokun](https://avatars.githubusercontent.com/u/198276?v=4)](https://github.com/nijikokun "nijikokun (5 commits)")[![jskrivseth](https://avatars.githubusercontent.com/u/8071570?v=4)](https://github.com/jskrivseth "jskrivseth (4 commits)")[![thibaultcha](https://avatars.githubusercontent.com/u/1125431?v=4)](https://github.com/thibaultcha "thibaultcha (3 commits)")[![andreyvital](https://avatars.githubusercontent.com/u/967317?v=4)](https://github.com/andreyvital "andreyvital (3 commits)")[![sonicaghi](https://avatars.githubusercontent.com/u/1213643?v=4)](https://github.com/sonicaghi "sonicaghi (3 commits)")[![nikkobautista](https://avatars.githubusercontent.com/u/278104?v=4)](https://github.com/nikkobautista "nikkobautista (2 commits)")[![qpleple](https://avatars.githubusercontent.com/u/774546?v=4)](https://github.com/qpleple "qpleple (2 commits)")[![rauny-henrique](https://avatars.githubusercontent.com/u/21957273?v=4)](https://github.com/rauny-henrique "rauny-henrique (2 commits)")[![RusinovIG](https://avatars.githubusercontent.com/u/1404336?v=4)](https://github.com/RusinovIG "RusinovIG (2 commits)")[![Furgas](https://avatars.githubusercontent.com/u/715407?v=4)](https://github.com/Furgas "Furgas (2 commits)")[![jasir](https://avatars.githubusercontent.com/u/115066?v=4)](https://github.com/jasir "jasir (2 commits)")[![frankdee](https://avatars.githubusercontent.com/u/5252262?v=4)](https://github.com/frankdee "frankdee (2 commits)")[![cristianp6](https://avatars.githubusercontent.com/u/233734?v=4)](https://github.com/cristianp6 "cristianp6 (2 commits)")[![samsullivan](https://avatars.githubusercontent.com/u/3789442?v=4)](https://github.com/samsullivan "samsullivan (1 commits)")[![xcopy](https://avatars.githubusercontent.com/u/202339?v=4)](https://github.com/xcopy "xcopy (1 commits)")

---

Tags

httphttpsclientrestcurl

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rauny-henrique-unirest-php/health.svg)

```
[![Health](https://phpackages.com/badges/rauny-henrique-unirest-php/health.svg)](https://phpackages.com/packages/rauny-henrique-unirest-php)
```

###  Alternatives

[mashape/unirest-php

Unirest PHP

1.3k9.7M161](/packages/mashape-unirest-php)[apimatic/unirest-php

Unirest PHP

224.7M116](/packages/apimatic-unirest-php)[zoonman/pixabay-php-api

PixabayClient is a PHP HTTP client library to access Pixabay's API

3354.7k](/packages/zoonman-pixabay-php-api)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
