This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

A Nice HTTP Client For PHP

dev-master 2020-10-10 18:40 UTC

This package is auto-updated.

Last update: 2021-10-10 20:49:00 UTC


Phetch is the missing 80% use case HTTP client for PHP. Phetch did not invent anything new, rather it is borrowing and building these ideas & desires:

  • API is natural, comfortable, and pleasant to use
  • A Zttp like client without the Guzzle dependency
  • As approachable as HTTPie
  • Json by default / Sensible defaults
  • Lightweight wrapper of PHP stream (http, ssl) functionality
  • Has shallow stack traces
  • Service container friendly


$ composer require ralphschindler/phetch


GET With Query Parameters

// simple call to the Github API
$resp = Phetch\Phetch::withBearerAuth('abcdefghijklmnopqrstuvwxyz0123456789')
    ->get('', ['state' => 'all']);

$resp->json(); // the response body as an array

POST with body

$response = Phetch\Phetch::request()->post('', [
    'title' => 'My Issue',
    'body' => 'This is the body to my issue',


$response = Phetch\Phetch::request()->patch('', [
    'title' => 'My Issue Updated Title!',

DELETE, with special headers at call time

// locking github issues requires a special accept header
$response = Phetch\Phetch::request()->delete('',
    ['headers' => ['Accept' => 'application/vnd.github.sailor-v-preview+json']]

Other special helper methods

Setting a base url for repeated calls at the same web service:
$req = Phetch\Phetch::withBaseUrl('');
$respGet = $request->get(...);
$respPatch = $request->patch(...);
Without verifying the SSL Certificate
$page = Phetch\Phetch::withoutVerifying()->get('');
Not following redirects
$page = Phetch\Phetch::withoutRedirecting()->get('');
Basic Authentication
$page = Phetch\Phetch::withBasicAuth($username, $password)->get('');
Bearer authentication
$page = Phetch\Phetch::withBearerAuth($token)->get('');

As A Service Inside An Application

Often times you may want to pre-configure a request to be used with shared settings in different contexts. Additionally, you may want to build a web-service specific client.

Setup the service

Creating a service allows you to configure and share a PendingRequest object with as much boilerplate as necessary for your app to talk to a particular service. ($container is assumed to be some kind of service container.)

$githubWebService = Phetch\Phetch::createService(function ($pendingRequestPrototype) {
    $pendingRequestPrototype->withHeaders(['User-Agent' => 'My Applications Http Client v1.0.0'])

$container->share('github-web-service', $githubWebService);

Use the service somewhere in your application code (controller, service classes, etc)

The PhetchService now contains your prototypical PendingRequest object that is preconfigured for use everywhere in your application. Each time you call $service->request(), you will get a cloned/fresh PendingRequest object that you can interact with. State changes to this new object will not affect the service's pre-configured object:

/** @var \Phetch\PhetchService $github */
$github = $container->get('github-web-service');

// request() will always produce a fresh & pre-configured \Phetch\PendingRequest
$resp = $github->request()
    ->get('/repos/ralphschindler/phetch/issues', ['state' => 'closed']);


  • httpie command parsing
  • command line phetch client
  • curl adapter (good open source contribution would be nice!)