The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started



Learn more about the general concepts of Fractal.

A cursor is an unintelligent form of Pagination, which does not require a total count of how much data is in the database. This makes it impossible to know if the "next" page exists, meaning an API client would need to keep making HTTP Requests until no data could be found (404).
Data usually has relationships to other data. Users have posts, posts have comments, comments belong to posts, etc. When represented in RESTful APIs this data is usually "included" (a.k.a embedded or nested) into the resource. A transformer will contain includePosts() methods, which will expect a resource to be returned, so it can be placed inside the parent resource.
Fractal has a class named Manager, which is responsible for maintaining a record of what embedded data has been requested, and converting the nested data into arrays, JSON, YAML, etc. recursively.
Pagination is the process of dividing content into pages, which in relation to Fractal is done in two alternative ways: Cursors and Paginators.
A paginator is an intelligent form of Pagination, which will require a total count of how much data is in the database. This adds a "paginator" item to the response meta data, which will contain next/previous links when applicable.
A resource is an object which acts as a wrapper for generic data. A resource will have a transformer attached, for when it is eventually transformed ready to be serialized and output.
A Serializer structures your Transformed data in certain ways. There are many output structures for APIs, two popular ones being HAL and JSON-API. Twitter and Facebook output data differently to each other, and Google does it differently too. Serializers let you switch between various output formats with minimal effect on your Transformers.
Transformers are classes, or anonymous functions, which are responsible for taking one instance of the resource data and converting it to a basic array. This process is done to obfuscate your data store, avoiding Object-relational impedance mismatch and allowing you to even glue various elements together from different data stores if you wish. The data is taken from these complex data store(s) and made into a format that is more manageable, and ready to be Serialized.