S
S
Sergei Abramov2020-08-09 19:41:57
symfony
Sergei Abramov, 2020-08-09 19:41:57

Why is fosrestbundle needed in symfony?

Good evening!
I used to write in Yii2. Now I want to write a REST application in symfony, I'm studying examples. All sorts of lessons and examples on the network are quite simple, somewhere JsonResponse is used, and somewhere the fosrestbundle additional library is used. But nowhere is it explained, what for is it needed, since it is possible to do everything with regular means? If it were not needed, it would not exist, but it is. Can you explain what it is for? When should it be used and when not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2020-08-09
@PatriotSY

FOSRestBundle simplifies the creation of REST endpoints by converting method names to routes + taking on a number of basic functions to simplify the creation of a REST API on Symfony. For example, you need to give normal responses in case of errors and exceptions, and errors, after all, are very different. It's unpleasant when you seem to have a REST API, and it suddenly starts rendering HTML.
In general, of course, all this can be done by hand, but in fact, in the end, something close will work out, well, maybe except for routing.
In general, FOSRestBundle is not very large, there are much more powerful solutions for creating APIs in the Symfony ecosystem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question