PHPackages                             manuman85/hal-client - 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. manuman85/hal-client

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

manuman85/hal-client
====================

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

1.0.1(2y ago)0582MITPHPPHP ^8.1

Since Oct 5Pushed 2y agoCompare

[ Source](https://github.com/manuman85/hal-client)[ Packagist](https://packagist.org/packages/manuman85/hal-client)[ Docs](https://github.com/manuman85/hal-client)[ RSS](/packages/manuman85-hal-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

HalClient
=========

[](#halclient)

A lightweight PHP client for consuming and manipulating [Hypertext Application Language (HAL)](https://tools.ietf.org/html/draft-kelly-json-hal)resources.

[![Build Status](https://github.com/jsor/hal-client/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsor/hal-client/actions/workflows/ci.yml)[![Coverage Status](https://camo.githubusercontent.com/6eeb90cffd926e66956dbe8f5b871a80791b6a6f2152c55886e885a175c88d88/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6a736f722f68616c2d636c69656e742f62616467652e7376673f6272616e63683d6d61696e26736572766963653d676974687562)](https://coveralls.io/github/jsor/hal-client?branch=main)

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

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

[](#installation)

Install the latest version with [Composer](http://getcomposer.org).

```
composer require jsor/hal-client
```

Check the [Packagist page](https://packagist.org/packages/jsor/hal-client) for all available versions.

### HTTP Client dependency

[](#http-client-dependency)

The Hal client requires a [HttpClientInterface](src/HttpClient/HttpClientInterface.php)implementation which can handle [PSR-7](http://www.php-fig.org/psr/psr-7/)requests and responses.

To use the default implementations shipped with this library, you need to install Guzzle 7, 6 or 5.

```
composer require guzzlehttp/guzzle:"^5.0||^6.0||^7.0"
```

Usage
-----

[](#usage)

We will use [Propilex](http://propilex.herokuapp.com) as an example API endpoint.

### Create the client

[](#create-the-client)

At a first step, we setup a `HalClient` instance.

```
use Jsor\HalClient\HalClient;

$client = new HalClient('http://propilex.herokuapp.com');
```

We can now set additional headers (eg. an Authorization header) which are sent with every request.

```
$client = $client->withHeader('Authorization', 'Bearer 12345');
```

Note, that a client instance is [immutable](https://en.wikipedia.org/wiki/Immutable_object), which means, any call to change the state of the instance returns a **new**instance leaving the original instance unchanged.

```
// Wrong!
$client->withHeader('Authorization', '...');
$resource = $client->get('/protected');

// Correct!
$client = $client->withHeader('Authorization', '...');
$resource = $client->get('/protected');
```

### Browse the API

[](#browse-the-api)

To start browsing through the API, we first get the root resource.

```
/** @var \Jsor\HalClient\HalResource $rootResource */
$rootResource = $client->root();
```

We now follow the `p:documents` link.

```
/** @var \Jsor\HalClient\HalLink $documentsLink */
$documentsLink = $rootResource->getFirstLink('documents');

$documentsResource = $documentsLink->get();

$totalDocuments = $documentsResource->getProperty('total');

foreach ($resource->getResource('documents') as $document) {
    echo $document->getProperty('title') . PHP_EOL;
}
```

If there is a second page with more documents, we can follow the `next` link.

```
if ($documentsResource->hasLink('next')) {
    $nextDocumentsResource = $documentsResource->getFirstLink('next')->get();
}
```

Ok, let's create a new document.

```
$newDocument = $documentsResource->post([
    'body' => [
        'title' => 'Sampl document',
        'body'  => 'Lorem ipsum'
    ]
]);
```

Oh noes! A typo in the document title. Let's fix it.

```
$changedDocument = $newDocument->put([
    'body' => [
        'title' => 'Sampe document',
        'body'  => $newDocument->getProperty('body')
    ]
]);
```

Damn, we give up.

```
$changedDocument->delete();
```

License
-------

[](#license)

Copyright (c) 2015-2021 Jan Sorgalla. Released under the [MIT License](LICENSE).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.3% 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

956d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83d40b12be3079825fbf9ecdcf8d620c60f1868832bf5efbdfdaee55acf41a6a?d=identicon)[manuman85](/maintainers/manuman85)

---

Top Contributors

[![jsor](https://avatars.githubusercontent.com/u/55574?v=4)](https://github.com/jsor "jsor (108 commits)")[![jeversen](https://avatars.githubusercontent.com/u/957260?v=4)](https://github.com/jeversen "jeversen (9 commits)")[![habl](https://avatars.githubusercontent.com/u/2447111?v=4)](https://github.com/habl "habl (4 commits)")

---

Tags

httpjsonapiclientresthal

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/manuman85-hal-client/health.svg)

```
[![Health](https://phpackages.com/badges/manuman85-hal-client/health.svg)](https://phpackages.com/packages/manuman85-hal-client)
```

###  Alternatives

[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)[serpapi/google-search-results-php

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

69114.3k](/packages/serpapi-google-search-results-php)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)[rap2hpoutre/jacky

Opinionated REST JSON HTTP API client for laravel

174.4k](/packages/rap2hpoutre-jacky)

PHPackages © 2026

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