This package is abandoned and no longer maintained. The author suggests using the package instead.

PHP library for generating Mason hypermedia documents

1.10.0 2016-03-28 17:28 UTC


Build Status Latest Stable Version Total Downloads Latest Unstable Version License

This project provides a PHP tool for building Hypermedia REST API's in Mason format.

At present, it includes a set of Mason Builder classes for producing data structures that can be passed to json_encode() for rendering Mason response bodies.


Here is a simple example:

use PhoneCom\Mason\Builder\Document;

$doc = new Document([
    'first_name' => 'Oscar',
    'last_name' => 'Grouch',
    'birthday' => 'Apr 1',
    'address' => 'Sesame Street'

$doc->addMetaProperty('@title', 'Oscar the Grouch')
    ->setProperty('clothing', 'Trash can')
    ->setControl('self', '');

echo json_encode($doc);

This produces the following data structure:

    "first_name": "Oscar",
    "last_name": "Grouch",
    "birthday": "Apr 1",
    "address": "Sesame Street",
    "clothing": "Trash can",
    "@meta": {
        "@title": "Oscar the Grouch"
    "@controls": {
        "self": {
            "href": ""


Mason is a Hypermedia RESTful API format first published in 2013 by Jørn Wildt. It combines lessons learned from years of API implementations and close study of other competing formats such as Hal, Collection+JSON, and JSON-LD. Each format has its strengths, but none has the desired balance of simplicity and features.

Mason-PHP was built to help promote Mason adoption within the PHP community, and to provide much needed tooling.


This project is integrated with Composer. You can put it in your composer.json as a dependency:

"require": {
    "phonecom/mason-laravel": "1.*"


Documentation is forthcoming. All public methods are documented inline, so at the moment, the best way to learn is to browse the code.


Run phpunit in the top folder. If you have the XDebug extension installed, you may also run it with the Code Coverage config which is provided separately, e.g. phpunit -c phpunit-coverage-html.xml


This project was created and is managed by We're building a hot new Hypermedia API and we chose Mason!

Pull requests are welcome.


This project is released under the MIT License. Copyright (c) 2015, Inc. See LICENSE for full details.