To install unirest-php with Composer, just add the following to your composer.json file:
{
"require-dev": {
"mashape/unirest-php": "3.*"
}
}
or by running the following command:
composer require mashape/unirest-php
Composer installs autoloader at ./vendor/autoloader.php
. to include the library in your script, add:
require_once 'vendor/autoload.php';
So you're probably wondering how using Unirest makes creating requests in PHP easier, let's look at a working example:
$apiKey = "key_from_rapidapi";
$text_for_detection = "Some text needed to detect its language";
$response = Unirest\Request::post("https://language-identification-prediction.p.rapidapi.com/v1/recognize-language/",
array(
"X-RapidAPI-Host" => "language-identification-prediction.p.rapidapi.com",
"X-RapidAPI-Key" => $apiKey,
"Content-Type" => "application/x-www-form-urlencoded"
),
array(
"text" => $text_for_detection
)
);
// full description of response here: https://rapidapi.com/BigLobster/api/language-identification-prediction/details
var_dump($response);