PHPackages                             yello/hack-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yello/hack-fetch

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yello/hack-fetch
================

Simple cURL wrapper for Hacklang

01Hack

Since Apr 10Pushed 2y agoCompare

[ Source](https://github.com/yello-xyz/hack-fetch)[ Packagist](https://packagist.org/packages/yello/hack-fetch)[ RSS](/packages/yello-hack-fetch/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

HackFetch
=========

[](#hackfetch)

Simple cURL wrapper for Hacklang. Basic HTTP client API inspired by [node-fetch](https://www.npmjs.com/package/node-fetch).

Installation
------------

[](#installation)

```
composer require yello/hack-fetch:dev-main
```

Common Usage
------------

[](#common-usage)

### Plain text or HTML

[](#plain-text-or-html)

```
use function Yello\HackFetch\fetch_async;

$response = await fetch_async('https://github.com/');
$body = await $response->textAsync();

echo $body;
```

### JSON response

[](#json-response)

```
use function Yello\HackFetch\fetch_async;

$response = await fetch_async('https://api.github.com/users/github');
$data = await $response->jsonAsync();

echo $data;
```

### Simple form post

[](#simple-form-post)

```
use function Yello\HackFetch\fetch_async;

$response = await fetch_async(
  'https://httpbin.org/post',
  shape('method' => 'POST', 'body' => 'a=1'),
);
$data = await $response->jsonAsync();

echo $data;
```

### Post with JSON

[](#post-with-json)

```
use function Yello\HackFetch\fetch_async;

$response = await fetch_async(
  'https://httpbin.org/post',
  shape(
    'method' => 'POST',
    'body' => \json_encode(shape('a' => 1)),
    'headers' => dict['content-type' => 'application/json'],
  ),
);
$data = await $response->jsonAsync();

echo $data;
```

### Accessing headers and other metadata

[](#accessing-headers-and-other-metadata)

```
use function Yello\HackFetch\fetch_async;

$response = await fetch_async('https://github.com/');

echo $response->ok() ? 'OK' : 'NOK';
echo $response->status();
echo $response->headers()['content-type'];
```

### Handling client and server errors

[](#handling-client-and-server-errors)

Note that 3xx-5xx responses are *not* exceptions.

```
use function Yello\HackFetch\fetch_async;

$response = await fetch_async('https://httpbin.org/status/400');
if ($response->ok()) {
  // status >= 200 && status < 300
} else {
  echo $response->status(); // 400
}
```

### Handling exceptions

[](#handling-exceptions)

Wrapping the fetch function into a try/catch block will catch all exceptions, including errors originating from core libraries, network errors, and operational errors.

```
use function Yello\HackFetch\fetch_async;

try {
  await fetch_async('https://domain.invalid');
} catch (\Exception $e) {
  echo $e->getMessage(); // Could not resolve host: domain.invalid
}
```

### Streams

[](#streams)

You can use async iterators to read the response body.

```
use function Yello\HackFetch\fetch_async;

$response =
  await fetch_async('https://httpbin.org/stream/3');

foreach ($response->body() await as $chunk) {
  echo $chunk;
}
```

### File download

[](#file-download)

```
use function Yello\HackFetch\fetch_async;

$file = fopen($file_name, 'w');
$response = await fetch_async('https://httpbin.org/image/png');
foreach ($response->body() await as $chunk) {
  fwrite($file, $chunk);
}
fclose($file);
```

### File upload

[](#file-upload)

```
use function Yello\HackFetch\fetch_async;

$file = fopen('test.png', 'r');
$response =
  await fetch_async('https://httpbin.org/anything', shape('file' => $file));
fclose($file);

echo $response->status();
```

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ab8d63caffff39eedb3a551ee3c7278e55e12e224c6778e3a981658b89aa91c?d=identicon)[hverlind](/maintainers/hverlind)

---

Top Contributors

[![hverlind](https://avatars.githubusercontent.com/u/6898258?v=4)](https://github.com/hverlind "hverlind (66 commits)")

### Embed Badge

![Health badge](/badges/yello-hack-fetch/health.svg)

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

###  Alternatives

[wallacemartinss/filament-icon-picker

A beautiful icon picker component for Filament v5 using blade-ui-kit/blade-icons

4723.9k35](/packages/wallacemartinss-filament-icon-picker)[eminos/statamic-tabs

A Statamic addon to be able to group fields into tabs.

1572.4k](/packages/eminos-statamic-tabs)

PHPackages © 2026

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