haruncpi/http

Simple HTTP client for PHP

v1.0.1 2022-03-12 13:58 UTC

This package is auto-updated.

Last update: 2024-04-12 18:59:55 UTC


README

Install

composer require haruncpi/http

Import class

use Haruncpi\Http\Http;

GET request

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

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

POST request

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

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

More options

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

Useful methods

$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