Normalization and Denormalization in ApiPlatform

Spread the love

I have read the docs over at api-platform.com a few times about Normalization and Denormalization. And it just didn’t click. I didn’t see why I would ever need it.

Now, recently, my day job decided we wanted a “central data store” which would serve multiple businesses and multiple interfaces. We found the ideal solution was Normalization groups even on controllers, where we can specify what data for a specific group. Of course that in itself doesn’t do that, be we couple it with Symfony’s security. Only certain groups have access to the “global” api’s, the base entity, or the /api route, however you like to call it.

Then we put business logic in custom controllers, and match those to routes and groups for a specific need. The result was pretty awesome. We manage a datastore which we have never made public before. Now we can control the data, depth of data, and who gets what by combining the Symfony user roles and API Platform normalization.

Well, I don’t know if I can explain it well, but as far as the code… it was a lightbulb moment.