Skip to content
HTTP client for Laravel, powered by Symfony components
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Laravel HTTP client


composer require ivan770/laravel-httpclient


// Obtaining instance via Facade alias
use HttpClient;
// You can use Facade class to access HttpClient
use Ivan770\HttpClient\Facade;
// Or, you can obtain HttpClient instance directly
use Ivan770\HttpClient\HttpClient;
public function method(HttpClient $client)

Sending requests

You can also use Symfony HttpClient documentation

$response = $client->get("");
$response = $client->get("", ["query" => ["key" => "value"]]);
$response->getContent(); // Get response body, or collection, if response is JSON
$response->toCollection(); // Transform JSON response to collection
$response->getStatusCode(); // Get response status code
$response->getHeaders(); // Get response headers

// You can use HTTP request methods as client methods
$client->post("", ["body" => ["key" => "value"]]);
$client->post("", ["json" => ["key" => "value"]]);

Using Request class

HttpClient provides ability to create "request classes".


use Ivan770\HttpClient\HttpClient;
use Ivan770\HttpClient\Request\Request;
use Ivan770\HttpClient\Response\MockResponse;

class HttpBinGet extends Request
    // Request URL
    protected $resource = "";

    // Request method
    protected $method = "GET";

    // This method is called on request init.
    // Here, you are able to use builder to modify your request
    protected function defaultAttach(HttpClient $client)

    protected function tests(){
        return [
            "success" => MockResponse::make("Hello World!"),

// Execute request

// Execute request and receive result

// Modify request using "attach" method.
app(HttpBinGet::class)->attach(function (HttpClient $client) {
    $client->headers(["test" => true]);

// Request also forwards calls to HttpClient
app(HttpBinGet::class)->headers(["test" => true])->execute();

// Mock responses
$response = app(HttpBinGet::class)->mock("success");

$response->getContent(); // "Hello World!"
$response->getStatus(); // 200
$response->getHeaders(); // []

BrowserKit usage


use Ivan770\HttpClient\Request\Request;
use Ivan770\HttpClient\Contracts\PassToBrowserKit;

// Just implement PassToBrowserKit contract to start using BrowserKit
class HttpBinGet extends Request implements PassToBrowserKit
    // Request URL
    protected $resource = "";

    // Request method
    protected $method = "GET";

Request builder

You can send your request parameters directly to client methods, but you can also use fluent request builder.

// Add data to request
$client->query(["key" => "value"])->get("")
$client->body(["key" => "value"])->post("")
$client->json(["key" => "value"])->post("")

// Add custom headers to request
$client->headers(["key" => "value"])->get("");

// Ignore redirects

// Proxy

// Authentication
$client->auth("auth_basic", ["username", "password"])->get("");
$client->authBasic(["username", "password"])->get("");

Arrayable parsing

You can use any Arrayable class (Eloquent models, collections, etc.) as data source for request

$model = User::find(1);

Data pipelining

If illuminate/pipeline is installed, you can send your data through pipelines. If not, you can still pass your data to Closure

$response = $client->get("");

// Pass data to Closure
$response->then(function ($data) {
    return $data;

// Use Laravel pipelines
$pipes = [
$response->pipeline()->through($pipes)->then(function ($data) {
    return $data;
You can’t perform that action at this time.