Tools for Hypermedia REST API development in PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
hooks
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpci.yml
phpunit-coverage-html.xml
phpunit.xml

README.md

Mason PHP

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.

Example

Here is a simple example:

<?php
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', 'http://example.com/characters/oscar');

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": "http://example.com/characters/oscar"
        }
    }
}

Motivation

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.

Installation

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

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

Usage

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

Tests

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

Contributors

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

Pull requests are welcome.

License

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