PHP code example of chaoswd / http

1. Go to this page and download the library: Download chaoswd/http 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/ */

    

chaoswd / http example snippets




haos\Http\Http;

$http = new Http();

// Basic GET request
$response = $http->get('https://jsonplaceholder.typicode.com/todos/1');

// $response is now a response object - use `json()`, `object()`, or `array()` for which response type you want.
var_dump($response->json());

$response = $http->post('https://example.com/api/posts', [
    'title' => 'Chaos Framework',
    'body'  => 'Lightweight HTTP client test',
]);

$http = new Chaos\Http\Http();

$http->withHeaders([
    'Authorization' => 'Bearer YOUR_TOKEN_HERE',
    'Accept' => 'application/json'
]);

$response = $http->get('https://api.example.com/user')->json();