PHPackages                             mostka/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. [API Development](/categories/api)
4. /
5. mostka/hal-client

ActiveLibrary[API Development](/categories/api)

mostka/hal-client
=================

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

00PHP

Since Mar 28Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (1)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

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d6d558226302620ec462f64672e9dc81609227626923a808005641e76e8c38f?d=identicon)[tito10047](/maintainers/tito10047)

---

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)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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