1. Go to this page and download the library: Download darshphpdev/httpclient 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/ */
// In your controller
// Use The Helper class HttpClient to send http requests
use HttpClient;
// Get Request
HttpClient::get('https://jsonplaceholder.typicode.com/posts');
// Get Request with params
HttpClient::get('https://jsonplaceholder.typicode.com/posts', ['limit' => 3]);
// Hits https://jsonplaceholder.typicode.com/posts?limit=3
// Get Request with headers
HttpClient::get('https://jsonplaceholder.typicode.com/posts', [], ['Content-Type' => 'application/json']);
// Post Request
HttpClient::post('https://jsonplaceholder.typicode.com/posts');
// Post Request with body
HttpClient::post('https://jsonplaceholder.typicode.com/posts', ['title' => 'HttpClient Package']);
// Post Request with body & headers
HttpClient::post('https://jsonplaceholder.typicode.com/posts',[
'title' => 'HttpClient Package'
] , [
'Content-Type' => 'application/json'
]);
// FOR FULL USAGE, SEE BELOW..