bigz/halapi
HAL JSON representation helper for HATEOAS APIs. Uses annotations and conventions to expose entities with links/relations, with pluggable URL generator, annotation reader, object manager, and pagination. Symfony-friendly today; aiming for framework-agnostic/PSR.
links: { self: { href: "/users/1" } }).Response::json()) or middleware (e.g., TransformsResources).Illuminate\Http\Response or Illuminate\Routing could require forks.404 with error object).spatie/hal-json-api, nesbot/carbon for dates in HAL) with active support?Response::cache()) interact with dynamic HAL links?/users endpoint) or is it an all-or-nothing change?php:8.2-cli)./users) using a middleware or decorator pattern:
// Example: Wrap Laravel's Response
$response = new Response($data);
$halResponse = (new HalApi())->addLinks($response, $user);
return $halResponse;
GET /users/{id}).GET /users with next/prev links).Accept: application/hal+json header).Illuminate\Http\Response: Create a custom HalResponse class extending Laravel’s Response.public function handle($request, Closure $next) {
$response = $next($request);
return tap($response)->addHalLinks($request->user());
}
Illuminate\Http\Resources\Json\JsonResource to include HAL links:
public function toArray($request) {
return array_merge(parent::toArray($request), [
'links' => [
'self' => route('users.show', $this->id),
],
]);
}
HttpFoundation). Use symfony/http-foundation:^5.4 if needed.| Step | Task | Dependencies | Risk |
|---|---|---|---|
| 1 | PHP 8.x Compatibility Test | Docker, PHP 8.2 | High (if unpatched) |
| 2 | Basic HAL Link Injection | Laravel 10.x, HalApi | Medium |
| 3 | Middleware Integration | Route middleware | Low |
| 4 | API Resource Extension | Eloquent models | Low |
| 5 | Client-Side Validation | Postman/Newman | Medium |
| 6 | Performance Benchmarking | Blackfire, Laravel Debugbar | Low |
| 7 | Documentation Update | Swagger/OpenAPI (if hybrid) | Low |
response_size in Prometheus).4xx/5xx for malformed HAL links (e.g., broken href URLs).GET /users?with=orders,addresses)./users/{id}/orders links change).user.orders) risks N+1 without eager loading.How can I help you explore Laravel packages today?