PHPackages                             los/los-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. los/los-api-client

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

los/los-api-client
==================

REST API Client using Hal

1.0.3(10y ago)3437[1 issues](https://github.com/Lansoweb/LosApiClient/issues)MITPHPPHP ^5.5|^7.0

Since Oct 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Lansoweb/LosApiClient)[ Packagist](https://packagist.org/packages/los/los-api-client)[ Docs](https://github.com/LansoWeb/LosApiClient)[ RSS](/packages/los-los-api-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (5)Used By (0)

Api Client for Restful API
==========================

[](#api-client-for-restful-api)

[![Build Status](https://camo.githubusercontent.com/663ae79335bbaac98a47ba352c69fe0e6011fde1e69478a89c3a1e1fdc04b9f7/68747470733a2f2f7472617669732d63692e6f72672f6c616e736f7765622f6c6f732d6170692d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lansoweb/los-api-client)

LosApiClient is a library to consume Restful APIs using Hal (json or xml) like [Apigility](http://apigility.org).

Can be used with pure PHP or any PHP framework, like ZendFramework 2 and Zend-Expressive.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.6
- Zend Http &gt;= 2.4
- Zend ModuleManager &gt;= 2.5
- Zend ServiceManager &gt;= 2.5
- nocarrier/hal &gt;= 0.9

Installation
------------

[](#installation)

### Using composer (recommended)

[](#using-composer-recommended)

```
php composer.phar require los/los-api-client
```

### Configuration

[](#configuration)

You need to configure at least the Api URI.

If using a framework that implements `container-interopt`, you can use the following configuration:

Copy the los-api-client.global.php.dist from this module to your application's config folder and make the necessary changes.

For more information about the http-client options, please check the official documentation at [Zend\\Http\\Client options](http://framework.zend.com/manual/current/en/modules/zend.http.client.html#configuration).

```
'los_api_client' => [
    'uri' => 'https://localhost:8000',
    'depth' => 0,
    'http_client' => [
        'options' => [
            'timeout'       => 60,
            'sslverifypeer' => false,
            'keepalive'     => true,
            'adapter'       => 'Zend\Http\Client\Adapter\Socket',
        ],
    ],
    'headers' => [
        'Accept'       => 'application/hal+json',
        'Content-Type' => 'application/json',
    ],
]
```

Usage
-----

[](#usage)

### Creating the client

[](#creating-the-client)

You can use the `LosApiClient\Api\ClientFactory` usign the above configuration or manually:

```
$httpClient = new Zend\Http\Client('http://127.0.0.1', []);
$client = new LosapiClient\Apt\Client($httpClient, 10);
```

Injecting a Cerberus Circuit Breaker
------------------------------------

[](#injecting-a-cerberus-circuit-breaker)

You can use the client with a circuit breaker to control failures and success and avoid uncessary attempts.

More information about cerberus on it's [own repository](https://github.com/mt-olympus/cerberus).

```
$httpClient = new Zend\Http\Client('http://127.0.0.1', []);
$storage = Zend\Cache\StorageFactory\StorageFactory::factory([
            'adapter' => [
                'name' => 'memory',
                'options' => [
                    'namespace' => 'my-service',
                ],
            ],
            'plugins' => [
                'exception_handler' => [
                    'throw_exceptions' => false,
                ],
            ],
        ]);
$cerberus = new Cerberus($storage, 2, 2);

// Create a new client
$client = new LosapiClient\Apt\Client($httpClient, 10, $cerberus, 'my-service);

// Or add it to a previously created client
$client->setCircuitBreaker($cerberus);
$client->setServiceName('my-service');
```

### Single resource

[](#single-resource)

```
/* @var \LosApiClient\Api\Client $client */
$client = $this->getServiceLocator()->get('los.api.client');
/* @var \LosApiClient\Resource\Resource $ret */
$ret = $client->get('/album/1');

// $data is an array with all data and resources (_embedded) from the response
$data = $ret->getData();

// $data is an array only with data from the response
$data = $ret->getData(false);
```

### Collection

[](#collection)

```
/* @var \LosApiClient\Api\Client $client */
$client = $this->getServiceLocator()->get('los.api.client');

// Setting depth of _embedded resources to 10
$client->setDepth(10);

/* @var \LosApiClient\Resource\Resource $ret */
$ret = $client->get('/album',['year' => 2015]);

// $data is an array with all data and resources (_embedded) from the response
$data = $ret->getData();

// $data is an array with the first album resource from the response
$data = $ret->getFirstResource('album');

// $data is an array with the all album resources from the response
$data = $ret->getResources('album');

// $data is an array with the all resources from the response
$data = $ret->getResources();
```

### Paginator

[](#paginator)

This module provides a paginator helper.

```
/* @var \LosApiClient\Api\Client $client */
$client = $this->getServiceLocator()->get('los.api.client');
/* @var \LosApiClient\Resource\Resource $ret */
$ret = $client->get('/album',['year' => 2015]);

// Returns how many items a page can have
$ret->getPaginator()->getPageSize();

// Returns how many pages the response has
$ret->getPaginator()->getPageCount();

// Returns how many items the response has (across all pages)
$ret->getPaginator()->getTotalItems();

// Returns the current page
$ret->getPaginator()->getPage();
```

You can easily loop through the pages:

```
/* @var \LosApiClient\Api\Client $client */
$client = $this->getServiceLocator()->get('los.api.client');
$page = 1;
do {
    /* @var \LosApiClient\Resource\Resource $ret */
    $ret = $client->get('/album',[
        'year' => 2015,
        'page' => $page;
    ]);
    $data = $ret->getData();
    $page++;
} while ($ret->getPaginator()->hasMorePages());
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~14 days

Total

4

Last Release

3817d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.6

1.0.1PHP ^5.5|^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b54dffc1ebcb317a0cf825a781ab6c5f30980e9abd0d0a3f9c68830cb05c014?d=identicon)[Lansoweb](/maintainers/Lansoweb)

---

Top Contributors

[![Lansoweb](https://avatars.githubusercontent.com/u/2109813?v=4)](https://github.com/Lansoweb "Lansoweb (22 commits)")

---

Tags

apiclientresthalzf2

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/los-los-api-client/health.svg)

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

###  Alternatives

[zfr/zfr-rest

Zend Framework 2 REST Module.

8120.6k](/packages/zfr-zfr-rest)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69114.3k](/packages/serpapi-google-search-results-php)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[artesaos/laravel-linkedin

Linkedin API integration for Laravel and Lumen 5

5666.5k](/packages/artesaos-laravel-linkedin)[jarischaefer/hal-api

Enhances your HATEOAS experience by automating common tasks.

291.4k](/packages/jarischaefer-hal-api)

PHPackages © 2026

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