filmov
tv
Create Three Symfony Back Ends - Part #22 - GET data from FOSRESTBundle
Показать описание
We can now POST data into our Symfony 4 and FOSRESTBundle API. We've seen how we can send in data either as JSON, or XML, and both are supported just fine. Now let's GET some data back out of our API.
When we generated the Album entity, Symfony's Maker Bundle also created src/Repository/AlbumRepository for us.
The AlbumRepository, via extends (inheritance), gives us access to all the standard Doctrine helper methods like find, findAll, findOneBy, and so on.
We'll only need the find method.
Our GET route will expect the API consumer to pass in an ID via the URL.
We'll take the requested $id and use this for querying for Album entities.
Then, all we need to do is return this object from our controller method, wrapped in a View.
When we generated the Album entity, Symfony's Maker Bundle also created src/Repository/AlbumRepository for us.
The AlbumRepository, via extends (inheritance), gives us access to all the standard Doctrine helper methods like find, findAll, findOneBy, and so on.
We'll only need the find method.
Our GET route will expect the API consumer to pass in an ID via the URL.
We'll take the requested $id and use this for querying for Album entities.
Then, all we need to do is return this object from our controller method, wrapped in a View.