Answer the question
In order to leave comments, you need to log in
How to work with Rest in Symfony?
It is required to work with api in Symfony 4. It is only necessary to receive data, without update, delete.
I found a suitable DoctrineRestDriver lib to work with the rest api as a base. I have not seen any other serious solutions for Symfony. I study the frame and do not know many solutions.
Problem.
In my case, the format of api responses does not match at all with the one proposed in DoctrineRestDriver. Instead of the conditional body, there is meta and data. The answer itself is already stored in data. Having studied the library, I realized that I can’t somehow customize the behavior of the parser. Inside, everything is rigidly made and classes cannot be replaced in any way.
There is a question in the issues of the project: what to do if the format of the response and request is different. They also answer that either is not intended for this. Apparently, who did not fit - we pass.
I can fork and add support for interfaces. Or even just rewrite the lib for yourself. Perhaps somehow in the frame to override the class. But I'm not sure if this is the right way to go. Too much is not suitable for my task. What if at all to make a small layer using a conditional gazzle and make calls in the repositories?
Answer the question
In order to leave comments, you need to log in
Do you want to work with the API through a docrine?
Take a look at https://github.com/doctrine/skeleton-mapper and the example implementation https://github.com/Coffreo/ceph-odm
Yes, you will have to implement some things, but you won't depend on the formats arrived by nails provided by DoctrineRestDriver
Does it just make sense?
If you need to implement "mixed" entities, for example, you have a Product, and the data of this Product is in the API - the ideal solution is to implement data loading on the postLoad of the Doctrine event.
Need objects, not raw data from an API? Look in the direction of the same JMS or Symphony serializer, which is enough in most cases.
But all this is justified if you really need to stick the work with the API under the Doctrine abstraction ...
> What if you even make a small layer using a conditional gazzle and make calls in the repositories?
The implementations that I have met in real projects - in 99% of cases this is exactly what they do. (In some - unfortunately, and in some - fortunately, because it is extremely easy to maintain)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question