PHP code example of darshphpdev / httpclient

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/ */

    

darshphpdev / httpclient example snippets


'providers' => [
    // ...
    DarshPhpDev\\HttpHelper\\HttpClientServiceProvider::class,
];

php artisan vendor:publish --tag="httpclient"

// 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..

HttpClient::post('https://jsonplaceholder.typicode.com/posts', 
	['title' => 'HttpClient Package'],
	['Content-Type' => 'application/x-www-form-urlencoded'],
	'form_params'
);
HttpClient::post('https://jsonplaceholder.typicode.com/posts', 
	['name' => 'myFile', 'content' => 'path/to/file'], 
	['Content-Type' => 'multipart/form-data'], 
	'multipart'
);
// and so on..