PHPackages                             level3/resource - 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. level3/resource

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

level3/resource
===============

Level3 Resource is a library for representing resources and consuming in different hypermedia formats.

v0.0.1(12y ago)1641.5k↓26.9%62MITPHPPHP &gt;=5.4.0

Since Nov 25Pushed 12y ago3 watchersCompare

[ Source](https://github.com/level3php/resource)[ Packagist](https://packagist.org/packages/level3/resource)[ Docs](http://github.com/level3php/resource)[ RSS](/packages/level3-resource/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (2)

Level3 Resource [![Build Status](https://camo.githubusercontent.com/f448e7644a911cf66983c49238e821451274cee72f2fdced2fe7f853e5e3af59/68747470733a2f2f7472617669732d63692e6f72672f6c6576656c337068702f7265736f757263652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/level3php/resource)
=====================================================================================================================================================================================================================================================================================================

[](#level3-resource-)

Level3 Resource is a library for representing and consuming resources in different [hypermedia](http://en.wikipedia.org/wiki/Hypermedia)formats.

A resource in a \[HATEOAS API\] () must describe its own capabilities and interconnections, which is the third level of [Three Levels of the REST Maturity Model](http://www.infoq.com/news/2010/03/RESTLevels)

### Why Hypermedia?

[](#why-hypermedia)

As you can read in the prologue of [Designing Hypermedia APIs](http://www.designinghypermediaapis.com/) book:

> Hypermedia APIs embrace the principles that make the web great: flexibility, standardization, and loose coupling to any given service. They take into account the principles of systems design [enumerated by Roy Fielding in his thesis](http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm), but with a little less sytems theory jargon.

> Hypermedia designs scale better, are more easily changed and promote decoupling and encapsulation, with all the benefits those things bring. On the downside, it is not necessarily the most latency-tolerant design, and caches can get stale if you're not careful. It may not be as efficient on an individual request level as other designs.

> \-- [Steve Klabnik](http://www.steveklabnik.com/)

### Which Hypermedia specification should I use?

[](#which-hypermedia-specification-should-i-use)

Hypermedia is being defined these days. Only the best APIs implement Hypermedia. Currently there is no de facto standard, so you must choose between the differents specifications.

Level3 Resource currenly implements or is planned to implement these specifications:

- [HAL](http://stateless.co/hal_specification.html): This is the most common and active. It has a JSON and a XML version.
- [Siren](https://github.com/kevinswiber/siren): Currently being defined. It implements some useful things like actions, classes, etc.
- [Collection+JSON](http://amundsen.com/media-types/collection/): This is fully designed to be a CRUD oriented API.

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

[](#requirements)

- PHP 5.4.x
- hampel/json &gt;= 1.0

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

[](#installation)

The recommended way to install Level3 Resource is [through composer](http://getcomposer.org). You can see [the package information on Packagist.](https://packagist.org/packages/level3/resource)

```
{
    "require": {
        "level3/resource": "dev-master"
    }
}
```

Examples
--------

[](#examples)

### Writer

[](#writer)

#### Basic Resource with Link as `application/hal+json`

[](#basic-resource-with-link-as-applicationhaljson)

```
use Level3\Resource\Link;
use Level3\Resource\Resource;
use Level3\Resource\Format\Writer\HAL;

$resource = new Resource();
$resource->setURI('/foo');
$resource->setLink('foo', new Link('/bar'));
$resource->setData([
    'foo' => 'bar',
    'baz' => 'qux'
]);

$writer = new HAL\JsonWriter(true);
echo $writer->execute($resource);
```

```
{
    "foo": "bar",
    "baz": "qux",
    "_links": {
        "self": {
            "href": "/foo"
        },
        "foo": {
            "href": "/bar"
        }
    }
}
```

#### Resource with embedded resources as `aapplication/vnd.siren+json`

[](#resource-with-embedded-resources-as-aapplicationvndsirenjson)

```
use Level3\Resource\Link;
use Level3\Resource\Resource;
use Level3\Resource\Format\Writer\Siren;

$resource = new Resource();
$resource->setRepositoryKey('index');
$resource->setURI('/index?page=2');
$resource->setLink('prev', new Link('/index?page=1'));
$resource->setLink('next', new Link('/index?page=3'));
$resource->addData('count', 5);

$subresource = [];
foreach (range(1, 5) as $value) {
    $subresource = new Resource();
    $subresource->addData('value', $value);

    $subresources[] = $subresource;
}

$resource->addResources('subresources', $subresources);

$writer = new Siren\JsonWriter(true);
echo $writer->execute($resource);
```

```
{
    "class": [
        "index"
    ],
    "properties": {
        "count": 5
    },
    "entities": [
        {
            "rel": "subresources",
            "class": [
                "index",
                "subresources"
            ],
            "properties": {
                "value": 1
            }
        },
        ...
        {
            "rel": "subresources",
            "class": [
                "index",
                "subresources"
            ],
            "properties": {
                "value": 5
            }
        }
    ],
    "links": [
        {
            "rel": "self",
            "href": "/index?page=2"
        },
        {
            "rel": "prev",
            "href": "/index?page=1"
        },
        {
            "rel": "next",
            "href": "/index?page=3"
        }
    ]
}
```

#### Resource with linked resource as `application/hal+xml`

[](#resource-with-linked-resource-as-applicationhalxml)

```
use Level3\Resource\Link;
use Level3\Resource\Resource;
use Level3\Resource\Format\Writer\HAL;

$author = new Resource();
$author->setURI('/john-doe');
$author->setTitle('John Doe');

$article = new Resource();
$article->setURI('/lorem-ipsum');
$article->addData('description', 'Lorem ipsum dolor sit amet ...');
$article->linkResource('author', $author);

$writer = new HAL\XMLWriter(true);
echo $writer->execute($article);
```

```

  Lorem ipsum dolor sit amet ...

```

### Reader

[](#reader)

#### Basic Resource with Link as `application/hal+json`

[](#basic-resource-with-link-as-applicationhaljson-1)

```
use Level3\Resource\Format\Reader\HAL;

$json = '{"foo":"bar","baz":"qux","_links":{"self":{"href":"/foo"},"foo":{"href":"/bar"}}}';

$reader = new HAL\JsonReader();
$resource = $reader->execute($json);
print_r($resource);
```

```
Level3\Resource\Resource Object
(
    [uri:protected] => /foo
    [links:protected] => Array
        (
            [foo] => Level3\Resource\Link Object
                (
                    [href:protected] => /bar
                )

        )

    [data:protected] => Array
        (
            [foo] => bar
            [baz] => qux
        )

)
```

Tests
-----

[](#tests)

Tests are in the `tests` folder. To run them, you need PHPUnit. Example:

```
$ phpunit --configuration phpunit.xml.dist

```

License
-------

[](#license)

MIT, see [LICENSE](LICENSE)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

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

4557d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1573114?v=4)[Máximo Cuadros](/maintainers/mcuadros)[@mcuadros](https://github.com/mcuadros)

---

Top Contributors

[![mcuadros](https://avatars.githubusercontent.com/u/1573114?v=4)](https://github.com/mcuadros "mcuadros (180 commits)")[![dripolles](https://avatars.githubusercontent.com/u/768061?v=4)](https://github.com/dripolles "dripolles (28 commits)")[![amartinj](https://avatars.githubusercontent.com/u/1821052?v=4)](https://github.com/amartinj "amartinj (6 commits)")[![filiptc](https://avatars.githubusercontent.com/u/2487390?v=4)](https://github.com/filiptc "filiptc (2 commits)")

---

Tags

apirestparserwriterreaderhalrestfulHATEOASSirenconsuming

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/level3-resource/health.svg)

```
[![Health](https://phpackages.com/badges/level3-resource/health.svg)](https://phpackages.com/packages/level3-resource)
```

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[tbbc/rest-util-bundle

Bundle for integrating tbbc/rest-util lib in a Symfony application.

30205.4k1](/packages/tbbc-rest-util-bundle)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)[slimpay/hapiclient

An HTTP Client using HAL as the format for resources.

14317.3k](/packages/slimpay-hapiclient)[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)
