PHP code example of haruncpi / http

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

    

haruncpi / http example snippets


use Haruncpi\Http\Http;

$url    = "https://jsonplaceholder.typicode.com/comments";
$data   = [ 'postId' => 1 ];

$response = HTTP::get( $url, $data );

$url    = "https://jsonplaceholder.typicode.com/posts";
$data   = [ 'title' => 'This is post title' ];

$response = HTTP::post( $url, $data );

$response = HTTP::get( $url, $data, $headers, $curlOptions );
$response = HTTP::post( $url, $data, $headers, $curlOptions );

$response->getStatusCode(); // to get response code
$response->getHeaders(); // to get all headers as array
$response->getHeader($name); // to get specific header
$response->getBody(); // to get raw response body
$response->getJson(); // to get body as assoc array
$response->getObject(); // to get body as object