PHPackages                             lessmore92/api-consumer - 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. [API Development](/categories/api)
4. /
5. lessmore92/api-consumer

ActivePackage[API Development](/categories/api)

lessmore92/api-consumer
=======================

Build REST API consumer easier than ever

v1.0.1(6y ago)49mitPHPPHP &gt;=7.3CI failing

Since Feb 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lessmore92/api-consumer)[ Packagist](https://packagist.org/packages/lessmore92/api-consumer)[ RSS](/packages/lessmore92-api-consumer/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

api-consumer
============

[](#api-consumer)

Build REST API consumer (client) easier than ever

### Installing

[](#installing)

Easily install it through Composer:

```
composer require lessmore92/api-consumer

```

### Support

[](#support)

```
PHP >=5.5

```

Usage
-----

[](#usage)

Easily extends your class from `ApiConsumer` and impalements `ConfigApi` method, and builds your awesome API Client.

Example:
--------

[](#example)

#### Below is the minimum requirement to start building API client: ***ConfigApi***

[](#below-is-the-minimum-requirement-to-start-building-api-client-configapi)

```
use Lessmore92\ApiConsumer\ApiConsumer;
use Lessmore92\ApiConsumer\Builders\ApiBuilder;

class MyApi extends ApiConsumer
{
    /**
     * @return ApiBuilder
     */
    protected function ConfigApi()
    {
        $api = new ApiBuilder();
        $api->setHeaderApiKey('API-TOKEN','X-API-Key');
        $api->setBaseUrl('https://MY-API-BASE-URL.COM/');
        return $api;
    }
}

```

If the api key needs to be placed in the query string use `setQueryApiKey` instead of `setHeaderApiKey`for example `$api->setQueryApiKey('API-TOKEN','TOKEN');`

---

### The Magic of `$this->Request()`

[](#the-magic-of-this-request)

By inheriting `ApiConsumer` your class will be able to utilize `$this->Request()` method, which supports chaining. With `$this->Request()` you will be able to access all the features and functionalities to make your request.

#### Define your first method to receive data from api: ***Simple GET Request***

[](#define-your-first-method-to-receive-data-from-api-simple-get-request)

To specify an endpoint to be called, you must use `->Endpoint()` method. After that by chaining `->Get()` method at the end, REQUEST METHOD is specified as `GET`.

```
use Lessmore92\ApiConsumer\ApiConsumer;
use Lessmore92\ApiConsumer\Builders\ApiBuilder;

class MyApi extends ApiConsumer
{
    /**
     * @return ApiBuilder
     */
    protected function ConfigApi()
    {
        $api = new ApiBuilder();
        $api->setHeaderApiKey('API-TOKEN','X-API-Key');
        $api->setBaseUrl('https://MY-API-BASE-URL.COM/');
        return $api;
    }

    public function Users()
    {
        $users = $this->Request()
                      ->Endpoint('users')
                      ->Get()
        ;

        return $users->body;
    }
}

```

In the above example we defined a method to `GET` `Users` list from server.

*By calling `Users()` method, in fact we are getting `https://MY-API-BASE-URL.COM/users`*

---

#### Make another request: Add ***Query String***

[](#make-another-request-add-query-string)

To pass data in query string (e.g to search, order or filter) you can use `->AddQueryString()` method.

```
public function SearchUsers($search)
{
    $users = $this->Request()
                  ->Endpoint('users')
                  ->AddQueryString('search', $search)
                  ->Get()
    ;

    return $users->json_body;
}

```

In the above example we defined a method to search in users.

*By calling `SearchUsers('alex')` method, in fact we are getting `https://MY-API-BASE-URL.COM/users?search=alex`*

---

#### Make another request: Get result in ***json*** format

[](#make-another-request-get-result-in-json-format)

To receive data as `json`, you must use `->AcceptJson()` method.

```
public function SearchUsers($search)
{
    $users = $this->Request()
                  ->Endpoint('users')
                  ->AcceptJson()
                  ->Get()
    ;

    return $users->json_body;
}

```

As you can see in the code above, by chaining `->AcceptJson()` in request we are telling to api server that we accept `json`, then in the `return` line we are returning a json formatted search result.

*For `json` data format, your api server must be able to provide json formatted response and support HEADER `'accept : application/json'`*

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~10 days

Total

2

Last Release

2286d ago

PHP version history (2 changes)v1.0PHP &gt;=5.5

v1.0.1PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1258149?v=4)[Mojtaba Bahrami](/maintainers/lessmore92)[@lessmore92](https://github.com/lessmore92)

---

Top Contributors

[![lessmore92](https://avatars.githubusercontent.com/u/1258149?v=4)](https://github.com/lessmore92 "lessmore92 (18 commits)")

---

Tags

api-clientapi-consumerapi-restclientconsumerjsonjson-apijson-parserjsonapiphpreceive-datarestrest-apirest-clientrestful-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lessmore92-api-consumer/health.svg)

```
[![Health](https://phpackages.com/badges/lessmore92-api-consumer/health.svg)](https://phpackages.com/packages/lessmore92-api-consumer)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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