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

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

amanank/hal-client
==================

A PHP client for interacting with HAL APIs.

v0.2.1-alpha(2mo ago)02.3k[6 issues](https://github.com/amanank/hal-client/issues)[1 PRs](https://github.com/amanank/hal-client/pulls)MITPHPPHP &gt;=7.2CI failing

Since Sep 11Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (10)Versions (23)Used By (0)

HAL API Client
==============

[](#hal-api-client)

A PHP client for interacting with HAL APIs. Tested with Laravel 8–12.

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

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

You can install the package via Composer. Run the following command in your terminal:

```
composer require amanank/hal-client
```

If you haven't already, make sure to include the Composer autoload file in your project:

```
require 'vendor/autoload.php';
```

### 2. Publish the Configuration File

[](#2-publish-the-configuration-file)

After installing the package, you can publish the configuration file using the following Artisan command:

```
php artisan vendor:publish --tag=config --provider="Amanank\HalClient\Providers\HalClientServiceProvider"
```

This will create a configuration file named `hal-client.php` in your `config` directory.

#### Note

[](#note)

Laravel's auto-discovery feature will automatically register the `HalClientServiceProvider` for you. You do not need to manually register it in your `config/app.php` file. For local development in this monorepo, the package is available via a path repository (`packages/*/*`) with symlinks enabled, so you can edit the package in place; in CI/prod, Composer will fall back to Packagist.

### 3. Configure `hal-client.php`

[](#3-configure-hal-clientphp)

After registering the service provider, you need to configure it. Create a configuration file named `hal-client.php` in your `config` directory with the following content:

```
return [
    'base_uri' => env('HAL_API_BASE_URI', 'https://example.com/api/v1/'),
    'headers' => [
        'Authorization' => 'Bearer ' . env('HAL_API_TOKEN'),
        'Accept' => 'application/hal+json',
    ],
];
```

Make sure to set the `HAL_API_BASE_URI` and `HAL_API_TOKEN` environment variables in your `.env` file:

```
HAL_API_BASE_URI=https://api.example.com
HAL_API_TOKEN=your-api-token
```

### 4. Generate Models

[](#4-generate-models)

To generate models from your HAL API, run the following commands in your terminal:

```
# Clear the application cache to ensure that any configuration changes are properly loaded
php artisan config:cache

# Generate models based on your HAL API schema
php artisan hal:generate-models

# Update the Composer autoloader to include the new models
composer dump-autoload
```

This will generate the necessary models based on your HAL API schema and ensure they are properly autoloaded.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

After generating the models, you can use them directly from the `Amanank\HalClient\Models\Discovered` namespace or extend them in your `App\Models` namespace.

#### Using Models Directly

[](#using-models-directly)

```
use Amanank\HalClient\Models\Discovered\User;
use Amanank\HalClient\Models\Discovered\Post;
use Amanank\HalClient\Models\Discovered\Tag;
use Amanank\HalClient\Models\Discovered\Comment;

// Create a new user
$user = new User();
$user->username = 'john.doe';
$user->email = 'john.doe@example.com';
$user->save();

// Create a new post
$post = new Post();
$post->title = 'My First Post';
$post->content = 'This is the content of my first post.';
$post->user()->associate($user);
$post->save();

// Create a new tag
$tag = new Tag();
$tag->name = 'PHP';
$tag->save();

// Create a new comment
$comment = new Comment();
$comment->content = 'Great post!';
$comment->post()->associate($post);
$comment->user()->associate($user);
$comment->save();
```

#### Extending Models

[](#extending-models)

You can also extend the generated models in your `App\Models` namespace:

```
namespace App\Models;

use Amanank\HalClient\Models\Discovered\User as DiscoveredUser;

class User extends DiscoveredUser {
    // Add your custom methods or properties here
}
```

#### Creating and Updating Models

[](#creating-and-updating-models)

```
use App\Models\User;
use App\Models\Post;
use App\Models\Tag;
use App\Models\Comment;

// Create a new user
$user = new User();
$user->username = 'john.doe';
$user->email = 'john.doe@example.com';
$user->save();

// Update a user
$user = User::find(1);
$user->email = 'new.email@example.com';
$user->save();
```

#### Searching Models

[](#searching-models)

You can get models using the `Model::get` method, which accepts parameters `$page = null`, `$size = null`, and `$sort = null`, and returns a `LengthAwarePaginator`.

Additionally, any search methods exposed by the HAL API can be used directly. For example, `User::findByLastName` returns a collection, and `User::getByEmail` returns a `User` or `null`.

```
use Amanank\HalClient\Models\Discovered\User;

// Get paginated users
$users = User::get($page = 1, $size = 10, $sort = 'username');

// Find users by last name
$usersByLastName = User::findByLastName('Doe');

// Get user by email
$userByEmail = User::getByEmail('john.doe@example.com');
```

#### Working with Relationships

[](#working-with-relationships)

```
use App\Models\User;
use App\Models\Post;
use App\Models\Tag;
use App\Models\Comment;

// Get user's posts
$user = User::find(1);
$posts = $user->posts;

// Get post's comments
$post = Post::find(1);
$comments = $post->comments;

// Attach a tag to a post
$post = Post::find(1);
$tag = Tag::find(1);
$post->tags()->attach($tag);

// Detach a tag from a post
$post->tags()->detach($tag);
```

#### Working with Enums

[](#working-with-enums)

Enums are located under the `Amanank\HalClient\Models\Discovered\Enums` namespace and are prefixed with the model name, such as `UserStatusEnum` and `PostStatusEnum`.

```
use Amanank\HalClient\Models\Discovered\Enums\UserStatusEnum;
use App\Models\User;

// Set user status
$user = User::find(1);
$user->status = UserStatusEnum::ACTIVE;
$user->save();

// Get users with a specific status
$activeUsers = User::where('status', UserStatusEnum::ACTIVE)->get();
```

### License

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

### Contributing

[](#contributing)

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Make your changes.
4. Commit your changes (`git commit -am 'Add new feature'`).
5. Push to the branch (`git push origin feature-branch`).
6. Create a new Pull Request.

### Support

[](#support)

If you have any questions or need support, please open an issue on the GitHub repository.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance86

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 94.5% 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 ~54 days

Recently: every ~134 days

Total

11

Last Release

74d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/538d6567a9a8cf21a7717ecdd6255881a414791a9bc0613e0f4dff0fc2c8c8a1?d=identicon)[amanank](/maintainers/amanank)

---

Top Contributors

[![amanank](https://avatars.githubusercontent.com/u/10206965?v=4)](https://github.com/amanank "amanank (52 commits)")[![AsfandYarAhmad](https://avatars.githubusercontent.com/u/67160854?v=4)](https://github.com/AsfandYarAhmad "AsfandYarAhmad (3 commits)")

---

Tags

phpapiclientresthal

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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