phonedotcom / mason-php
PHP library for generating Mason hypermedia documents
Installs: 374
Dependents: 2
Suggesters: 0
Security: 0
Stars: 24
Watchers: 32
Forks: 0
Open Issues: 0
Requires
- php: >=5.5
Requires (Dev)
README
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.