Skip to content

FetchPHP / JavaScript-inspired HTTP for PHP

Meet fetch()
for modern PHP.

A familiar JavaScript-inspired entry point, powered by Guzzle. Start with a simple request, then opt in to retries, streaming, and async workflows.

Install with Composer
composer require jerome/fetch-php

GETapi.example.test/v1/users/42

Illustrative example · no request is sent
request.php
$response = fetch(
    'https://api.example.test/v1/users/42',
);

if ($response->successful()) {
    $user = $response->json();
}
01 Compose a request02 Send with Guzzle03 Work with the response

Autoloading and offline test fakes omitted for clarity. View runnable examples →

Small API. Strong foundations.

PHP 8.3+ Guzzle 7.9+ Matrix 4 PSR-7 / PSR-18

A small surface. A capable client.

Start simple.
Stay in control.

One request shouldn’t need a ceremony. A growing application shouldn’t need a different HTTP client.

client.php
$client = fetch_client([
    'base_uri' => 'https://api.example.test/v1/',
    'headers' => ['Accept' => 'application/json'],
    'timeout' => 5,
]);

$response = $client->get('users');

Real API. Offline-tested examples. See the full source →

01

A fluent vocabulary.

Set headers, authentication, timeouts, and request defaults. Keep the details close to the call.

Configure requests
02

Responses you can work with.

Read JSON, inspect status codes, or work directly with the underlying PSR-7 message.

Handle responses
03

Your policies, in the pipeline.

Add retries, opt-in HTTP caching, middleware, and request validation as your application grows.

Explore the guides

Concurrency, with intention

More requests.
One clear flow.

Enable async transport on a handler. Compose its promises with Matrix. Work with the results when they’re ready.

Meet the async API
async() An explicit boundary. Synchronous helpers stay synchronous.
concurrent.php
use Fetch\Http\ClientHandler;
use Fetch\Testing\MockResponse;
use Fetch\Testing\MockServer;

$client = ClientHandler::create()->async();

$responses = await(all([
    'users' => $client->get('https://api.example.test/users'),
    'posts' => $client->get('https://api.example.test/posts'),
]));

Illustrative · autoloading and offline test fakes omitted. Runnable source ↗

Your next request starts here

Less ceremony.
More possibility.

Start with one request. Find your rhythm. The documentation takes it from there.

Released under the MIT License.