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.0(today)10MITPHPPHP ^8.2CI passing

Since Jun 23Pushed today1 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)[ RSS](/packages/jeffersongoncalves-laravel-zero-api-client/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

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

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

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

Code StyleLaravel Pint

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

28210.2M32](/packages/quickbooks-v3-php-sdk)[wrapi/slack

Wrapper for Slack Web API

54277.5k2](/packages/wrapi-slack)[eljam/guzzle-jwt-middleware

A jwt authentication middleware for guzzle 6

28750.0k3](/packages/eljam-guzzle-jwt-middleware)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

12261.2k1](/packages/e-moe-guzzle6-bundle)[dreamfactory/df-core

DreamFactory(tm) Core Components

1652.0k38](/packages/dreamfactory-df-core)[opgg/riotquest

RiotQuest, PHP RiotAPI client library that focused on multi request from OP.GG

172.6k](/packages/opgg-riotquest)

PHPackages © 2026

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