PHPackages                             jeffersongoncalves/laravel-zero-api-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. jeffersongoncalves/laravel-zero-api-client

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

jeffersongoncalves/laravel-zero-api-client
==========================================

Reusable base REST HTTP client for Laravel Zero CLIs: get/post/put/delete, pagination, Basic/Bearer auth and consistent API error handling.

v1.0.1(1mo ago)1362MITPHPPHP ^8.2CI passing

Since Jun 23Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/jeffersongoncalves/laravel-zero-api-client)[ Packagist](https://packagist.org/packages/jeffersongoncalves/laravel-zero-api-client)[ Docs](https://github.com/jeffersongoncalves/laravel-zero-api-client)[ GitHub Sponsors](https://github.com/jeffersongoncalves)[ RSS](/packages/jeffersongoncalves-laravel-zero-api-client/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (1)Dependencies (9)Versions (3)Used By (2)

[![laravel-zero-api-client](https://raw.githubusercontent.com/jeffersongoncalves/laravel-zero-api-client/main/art/jeffersongoncalves-laravel-zero-api-client.png)](https://raw.githubusercontent.com/jeffersongoncalves/laravel-zero-api-client/main/art/jeffersongoncalves-laravel-zero-api-client.png)

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

[](#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
------------

[](#installation)

```
composer require jeffersongoncalves/laravel-zero-api-client
```

Requires PHP `^8.2` and `guzzlehttp/guzzle ^7.10`.

Usage
-----

[](#usage)

### 1. Define your exception

[](#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.

```
use JeffersonGoncalves\LaravelZero\ApiClient\ApiException;

final class GitHubApiException extends ApiException
{
    // Optional: GitHub returns { "message": "..." }, already handled by the base.
}
```

### 2. Define your client

[](#2-define-your-client)

Extend `AbstractApiClient` and implement `newApiException()` to bind error handling to your exception type.

```
use JeffersonGoncalves\LaravelZero\ApiClient\AbstractApiClient;
use JeffersonGoncalves\LaravelZero\ApiClient\ApiException;
use JeffersonGoncalves\LaravelZero\ApiClient\Auth;

final class GitHubClient extends AbstractApiClient
{
    public function __construct(string $token)
    {
        parent::__construct('https://api.github.com', Auth::bearer($token));
    }

    protected function newApiException(int $statusCode, array $body): ApiException
    {
        return GitHubApiException::fromResponse($statusCode, $body);
    }

    public function repo(string $owner, string $repo): array
    {
        return $this->get("repos/{$owner}/{$repo}");
    }
}
```

### 3. Authentication

[](#3-authentication)

```
Auth::basic('user@example.com', 'api-token'); // Authorization: Basic base64(user:token)
Auth::bearer('access-token');                 // Authorization: Bearer access-token
```

Pass `null` for anonymous access, or override `authHeaders()` for a custom scheme.

### 4. Pagination

[](#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):

```
$all = $client->paginate(
    "repositories/{$workspace}/{$repo}/pullrequests",
    ['state' => 'OPEN'],
    fn (array $page) => $page['values'] ?? [],
    fn (array $page) => isset($page['next'])
        ? ['path' => $page['next'], 'query' => []]
        : null,
);
```

Offset pagination (Jira-style `startAt`/`maxResults`):

```
$all = $client->paginate(
    'search',
    ['startAt' => 0, 'maxResults' => 50],
    fn (array $page) => $page['issues'] ?? [],
    function (array $page, array $query) {
        $next = $query['startAt'] + $query['maxResults'];

        return $next >= ($page['total'] ?? 0)
            ? null
            : ['query' => ['startAt' => $next, 'maxResults' => $query['maxResults']]];
    },
);
```

Public API
----------

[](#public-api)

ClassPurpose`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
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

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

45d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Top Contributors

[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

api-clientclicomposerhttp-clientjeffersongoncalveslaravel-zerophpresthttpclirestGuzzlelaravel-zeroapi client

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jeffersongoncalves-laravel-zero-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/jeffersongoncalves-laravel-zero-api-client/health.svg)](https://phpackages.com/packages/jeffersongoncalves-laravel-zero-api-client)
```

###  Alternatives

[quickbooks/v3-php-sdk

The Official PHP SDK for QuickBooks Online Accounting API

28411.1M35](/packages/quickbooks-v3-php-sdk)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1064.9M19](/packages/xeroapi-xero-php-oauth2)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

293.1k](/packages/eslazarev-wildberries-sdk)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

37234.5k2](/packages/onesignal-onesignal-php-api)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11263.3k1](/packages/e-moe-guzzle6-bundle)[meteocontrol/vcom-api-client

HTTP Client for meteocontrol's VCOM API - The VCOM API enables you to directly access your data on the meteocontrol platform.

188.6k1](/packages/meteocontrol-vcom-api-client)

PHPackages © 2026

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