PHP


Requirements

cURL
PHP 5.4+

Installation

Using Composer

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

JSON
{
    "require-dev": {
        "mashape/unirest-php": "3.*"
    }
}

or by running the following command:

Text
composer require mashape/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:

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

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

Text
require_once 'vendor/autoload.php';

If you use Symfony2, autoloader has to be detected automatically.
You can see this library on Packagist.

Install from source

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

Shell
git clone git@github.com:Mashape/unirest-php.git 
PHP
require_once '/path/to/unirest-php/src/Unirest.php';

Usage

Creating a Request

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

PHP
$headers = array('Accept' => 'application/json');

$response = Unirest\Request::post("API_URL",
  array(
    "X-Mashape-Key" => "API_KEY"
  )
);