Download the PHP package jeffersongoncalves/laravel-zero-api-client without Composer
On this page you can find all versions of the php package jeffersongoncalves/laravel-zero-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeffersongoncalves/laravel-zero-api-client
More information about jeffersongoncalves/laravel-zero-api-client
Files in jeffersongoncalves/laravel-zero-api-client
Package laravel-zero-api-client
Short Description Reusable base REST HTTP client for Laravel Zero CLIs: get/post/put/delete, pagination, Basic/Bearer auth and consistent API error handling.
License MIT
Homepage https://github.com/jeffersongoncalves/laravel-zero-api-client
Informations about the package laravel-zero-api-client
laravel-zero-api-client
A small, self-contained base for building REST API client wrappers in Laravel Zero CLI
tools. It was extracted from the near-identical HTTP layers of the Bitbucket and Jira
CLIs and captures the shared 85%: get/post/put/delete, pagination, Basic/Bearer
authentication and consistent JSON error handling on top of Guzzle.
Why
Every API CLI ends up writing the same boilerplate: a Guzzle client, JSON decoding, a "throw a typed exception on 4xx" branch, and a pagination loop. This package owns that boilerplate so each concrete client only describes what is genuinely API-specific:
- which exception type to throw, and
- how to walk that API's particular pagination scheme.
It has no dependency on any credentials package - authentication is passed in through the constructor.
Installation
Requires PHP ^8.2 and guzzlehttp/guzzle ^7.10.
Usage
1. Define your exception
Extend ApiException. The base extractMessage() already understands the common error
shapes (error.message, message, errorMessages); override it only when your API is
different.
2. Define your client
Extend AbstractApiClient and implement newApiException() to bind error handling to
your exception type.
3. Authentication
Pass null for anonymous access, or override authHeaders() for a custom scheme.
4. Pagination
Pagination differs across APIs, so paginate() takes two callables: one to extract the
items from a page, one to describe the next request (or return null to stop).
Cursor pagination (Bitbucket-style next URL):
Offset pagination (Jira-style startAt/maxResults):
Public API
| Class | Purpose |
|---|---|
AbstractApiClient |
Base client: get, post, put, delete, paginate. Implement newApiException(). |
ApiException |
Abstract base exception with fromResponse() / extractMessage() and $statusCode / $response. |
Auth |
Immutable credential: Auth::basic(), Auth::bearer(). |
AuthType |
Basic / Bearer enum. |
Testing
License
MIT