PHPackages                             utopia-php/fetch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. utopia-php/fetch

ActiveLibrary[HTTP &amp; Networking](/categories/http)

utopia-php/fetch
================

A simple library that provides an interface for making HTTP Requests.

1.0.0(3mo ago)10187.3k↓15.1%3[1 PRs](https://github.com/utopia-php/fetch/pulls)8MITPHPPHP &gt;=8.1

Since Oct 10Pushed 3mo ago6 watchersCompare

[ Source](https://github.com/utopia-php/fetch)[ Packagist](https://packagist.org/packages/utopia-php/fetch)[ RSS](/packages/utopia-php-fetch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (20)Used By (8)

Utopia Fetch
============

[](#utopia-fetch)

Lite &amp; fast micro PHP library that provides a convenient and flexible way to perform HTTP requests in PHP applications.

Usage
-----

[](#usage)

Create an instance of the `Client` class to perform HTTP requests. The instance methods allow for setting request options like headers, timeout, connection timeout, and more.

The `fetch()` method on a `Client` instance accepts the following parameters:

- `url` - A **String** containing the URL to which the request is sent.
- `method` - A **String** containing the HTTP method for the request. The default method is `GET`.
- `body` - An **array** of data to send as the body of the request, which can be an associative array for form data or a JSON string.
- `query` - An **associative array** of query parameters.

The `Response` object returned by `fetch()` provides several methods to inspect the response:

- `isOk()` - Checks if the response status code is within the 200-299 range.
- `getBody()` - Retrieves the response body as a string.
- `getHeaders()` - Fetches the response headers as an associative array.
- `getStatusCode()` - Gets the response status code.
- `json()` - Decodes the response body to an associative array.
- `text()` - Alias for `getBody()`, returns the response body as a string.
- `blob()` - Returns the response body as a blob.

Examples
--------

[](#examples)

### GET Request

[](#get-request)

```
require_once __DIR__ . '/vendor/autoload.php';
use Utopia\Fetch\Client;

$client = new Client();
$url = 'https://httpbin.org/get';
$method = 'GET';
$query = ['foo' => 'bar'];

// Optionally set more configurations
$client
  ->setUserAgent('CustomUserAgent/1.0')
  ->setAllowRedirects(true)
  ->setMaxRedirects(1)
  ->setConnectionTimeout(10)
  ->setTimeout(30);

$resp = $client->fetch(
    url: $url,
    method: $method,
    query: $query
);

if ($resp->isOk()) {
    echo "Status Code: " . $resp->getStatusCode() . "\n";
    echo "Response Headers:\n";
    print_r($resp->getHeaders());
    echo "Response Body:\n";
    echo $resp->getBody();
} else {
    echo "Error: " . $resp->getStatusCode() . "\n";
}
```

### POST Request

[](#post-request)

```
require_once __DIR__ . '/vendor/autoload.php';
use Utopia\Fetch\Client;

$client = new Client();
$url = 'https://httpbin.org/post';
$method = 'POST';
$headers = ['Content-Type' => 'application/json'];
$body = ['name' => 'John Doe'];
$query = ['foo' => 'bar'];

// Set request headers
$client->addHeader('Content-Type', 'application/json');

$resp = $client->fetch(
    url: $url,
    method: $method,
    body: $body,
    query: $query
);

print_r($resp->json());
```

### Sending a file

[](#sending-a-file)

```
require_once __DIR__ . '/vendor/autoload.php';
use Utopia\Fetch\Client;

$client = new Client();
$url = 'http://localhost:8000/upload';
$method = 'POST';

// Ensure you set the appropriate Content-Type for file upload
$client->addHeader('Content-Type', 'multipart/form-data');

$filePath = realpath(__DIR__ . '/tests/resources/logo.png'); // Absolute path to the file
$body = ['file' => new \CURLFile($filePath, 'image/png', 'logo.png')];

$resp = $client->fetch(
    url: $url,
    method: $method,
    body: $body
);

print_r($resp->json());
```

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance78

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~83 days

Recently: every ~70 days

Total

11

Last Release

119d ago

Major Versions

0.5.1 → 1.0.02026-01-19

PHP version history (2 changes)0.1.0PHP &gt;=8.0

0.5.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/023f08a9df59f81cc4a04b1cebd20f45ede5db53ef2f9e9ad3d75f4c69be66b8?d=identicon)[eldadfux](/maintainers/eldadfux)

---

Top Contributors

[![abnegate](https://avatars.githubusercontent.com/u/5857008?v=4)](https://github.com/abnegate "abnegate (32 commits)")[![sahilsaha7773](https://avatars.githubusercontent.com/u/35343652?v=4)](https://github.com/sahilsaha7773 "sahilsaha7773 (32 commits)")[![christyjacob4](https://avatars.githubusercontent.com/u/20852629?v=4)](https://github.com/christyjacob4 "christyjacob4 (19 commits)")[![shimonewman](https://avatars.githubusercontent.com/u/23742426?v=4)](https://github.com/shimonewman "shimonewman (8 commits)")[![eldadfux](https://avatars.githubusercontent.com/u/1297371?v=4)](https://github.com/eldadfux "eldadfux (8 commits)")[![PineappleIOnic](https://avatars.githubusercontent.com/u/26739219?v=4)](https://github.com/PineappleIOnic "PineappleIOnic (5 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (4 commits)")[![loks0n](https://avatars.githubusercontent.com/u/22452787?v=4)](https://github.com/loks0n "loks0n (3 commits)")[![TorstenDittmann](https://avatars.githubusercontent.com/u/1759475?v=4)](https://github.com/TorstenDittmann "TorstenDittmann (2 commits)")[![basert](https://avatars.githubusercontent.com/u/1951610?v=4)](https://github.com/basert "basert (2 commits)")[![Meldiron](https://avatars.githubusercontent.com/u/19310830?v=4)](https://github.com/Meldiron "Meldiron (2 commits)")[![lohanidamodar](https://avatars.githubusercontent.com/u/6360216?v=4)](https://github.com/lohanidamodar "lohanidamodar (1 commits)")[![hmacr](https://avatars.githubusercontent.com/u/132386067?v=4)](https://github.com/hmacr "hmacr (1 commits)")[![ChiragAgg5k](https://avatars.githubusercontent.com/u/110609663?v=4)](https://github.com/ChiragAgg5k "ChiragAgg5k (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/utopia-php-fetch/health.svg)

```
[![Health](https://phpackages.com/badges/utopia-php-fetch/health.svg)](https://phpackages.com/packages/utopia-php-fetch)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
