ferryjs / ferry

Ferry is (yet another) REST API framework.
3 stars 3 forks source link

Output formatters: serializers (and transformers maybe) #5

Open joshuajabbour opened 9 years ago

joshuajabbour commented 9 years ago

One other layer we should think about is output formats. There are quite a few primary ones: JSON API, JSON HAL, JSON-LD, etc.

There's also possibly transformers, though this is less likely necessary in our case, and might be mitigated by hooks in resource handlers (though I could see using the default handlers, and just tweaking the format slightly). One source of inspiration here is Fractal.

desmondmorris commented 9 years ago

@joshuajabbour This is really interesting, I am not too familiar with either concept. Would there be a world where both exist? Can you give an example?

joshuajabbour commented 9 years ago

Yes, both definitely could exist. In Fractal, serializers are the general, non-resource-specific formats (e.g. JSON-HAL). Transformers are resource-specific, and mainly are for type coercion since PHP sucks at that, but can also be used to add properties to the result object, etc.

In our case, serializers will be an eventual must-have. Transformers may not be required, and may just be middleware that manipulates the result.