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.1.2(2mo ago)10248.8k↓11.9%4[1 issues](https://github.com/utopia-php/fetch/issues)[1 PRs](https://github.com/utopia-php/fetch/pulls)12MITPHPPHP &gt;=8.1

Since Oct 10Pushed 3w ago5 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 2d ago

READMEChangelog (10)Dependencies (8)Versions (29)Used By (12)

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

59

—

FairBetter than 98% of packages

Maintenance90

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor3

3 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 ~71 days

Recently: every ~32 days

Total

14

Last Release

65d 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 (33 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)")[![lohanidamodar](https://avatars.githubusercontent.com/u/6360216?v=4)](https://github.com/lohanidamodar "lohanidamodar (7 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 (4 commits)")[![ChiragAgg5k](https://avatars.githubusercontent.com/u/110609663?v=4)](https://github.com/ChiragAgg5k "ChiragAgg5k (3 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (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)")[![hmacr](https://avatars.githubusercontent.com/u/132386067?v=4)](https://github.com/hmacr "hmacr (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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M91](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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