PHPackages                             stratadox/rest-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. stratadox/rest-resource

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

stratadox/rest-resource
=======================

v0.3(6y ago)05MITPHPPHP &gt;=7.2CI failing

Since Jan 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Stratadox/RestResource)[ Packagist](https://packagist.org/packages/stratadox/rest-resource)[ RSS](/packages/stratadox-rest-resource/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (6)Versions (4)Used By (0)

Rest Resource
=============

[](#rest-resource)

HATEOAS-compatible Restful Resource descriptions, with formatters to represent the resources in json- or xml format.

[![Build Status](https://camo.githubusercontent.com/d8141ec4e803fd82af4c3d8ac39aac0ec684c4eca75235ba5b99611a8c77b41b/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f526573745265736f757263652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/RestResource)[![Coverage Status](https://camo.githubusercontent.com/a0bd7656202b22e01ee69703192aa0c33876abb5f5430808d75f1f61bd7452eb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f526573745265736f757263652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/RestResource?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c600e6b89ae6c569dd45ff04dc778e0c8421c7a11b327b50f4e42f9a1099dc86/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f526573745265736f757263652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/RestResource/?branch=master)

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

[](#installation)

Install with `composer require stratadox/rest-resource`

Example (json)
--------------

[](#example-json)

Resources formatted as json output:

```
 [
        [
            'id' => 1,
            'name' => 'Alice',
        ],
        [
            'id' => 2,
            'name' => 'Bob',
        ],
    ]
];
```

In json, one might have output like this:

```
{
  "people": [
    {
      "id": 1,
      "name": "Alice"
    },
    {
      "id": 2,
      "name": "Bob"
    }
  ]
}
```

However, we'd expect from xml something in the genre of:

```

        1
        Alice

        2
        Bob

```

Or

```

```

By default, the xml formatter uses [inflection](https://github.com/ICanBoogie/Inflector)to transform plurals into singular versions. As such, the aforementioned php array structure would indeed produce the expected xml. Any language supported by the inflector can be used, for example:

```

                1
                Alice

                2
                Bob

    ',
    $xml->from($resource)
);
```

Or, with less verbosity:

```
