Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON.
When building an API it is common for people to just grab stuff from the database and pass it
to json_encode()
. This might be passable for "trivial" API's but if they are in use by the public,
or used by an iPhone application then this will quickly lead to inconsistent output.
- Create a "barrier" between source data and output, so schema changes do not effect users
- Systematic type-casting of data, to avoid foreach()ing through and (bool)ing everything
- Embed (or nest) relationships for complex data structures
- Support the pagination of data results, for small and large data sets alike
- Generally ease the subtle complexities of outputting data in a non-trivial API
This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Via Composer
{
"require": {
"league/fractal": "0.7.*"
}
}
The following versions of PHP are supported by this version.
- PHP 5.3
- PHP 5.4
- PHP 5.5
- PHP 5.6
HHVM support is also experimentally supported. It basically works, but CodeSniffer installation is screwing it up on Travis-CI.
Fractal has full documentation, powered by Sculpin.
Contribute to this documentation in the sculpin branch.
- Switch return array to use instance properties in
transform()
- Implement HATEOAS/HAL links
- Add smart embed syntax, e.g:
?embed=foo:limit(5):order(something,asc)
$ phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.