PHP code example of interaapps / ulole-http-client

1. Go to this page and download the library: Download interaapps/ulole-http-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

interaapps / ulole-http-client example snippets


$client = new HttpClient("https://ping.intera.dev");

$authors = $client->get("/authors")
    ->send()
    ->json();

foreach ($authors as $author) {
    echo $author->name . "\n";
}

$success = $client->post("/authors", [
    "name" => "Author"
])
    ->bearer("HelloWorld")
    ->send()
    ->ok();
    
if ($success) {
    echo "Done!";
}
    




$request = $client->get("https://google.com");

$request->header("X-Header", "Value");
$request->bearer("ABCDE");

// Set Query Parameter
$request->query("key", "value");

// Set Body
$request->body("this-is-the-body=yey");

// Set Json Body
$request->json(["hello" => "world"]);


$request->timeout(150);

$request->followRedirects();
$request->notFollowRedirects();


$request->formData([
    "file" => new CURLFile("file.txt")
]);

$response = $request->send();

var_dump($response->json());
// From json model
var_dump($response->json(User::class));

var_dump($response->header("content-type"));
var_dump($response->body());
var_dump($response->status());
var_dump($response->ok());