I have a website that was created in Symfony2, and now I want many features of the site to be available in the mobile application now.
My idea is to add a simple URL variable, then it will output all the variables of the corresponding page request in JSON.
So, if I connect to
www.domain.com/profile/john-smith
It returns the HTML page as it is now. But if I go to
www.domain.com/profile/john-smith?app
It then returns a JSON object with name, age, and other profile information.
Then my application code gets JSON and processes.
I do not see any security issues, as these are just variables represented in JSON and HTML.
Having done this, I can create all the application code and just make calls with the same URL as the web page, which will return the variables in JSON and save the need for server-side work.
Question: How can I do this without changing each controller?
Can't I imagine an event listener to do this? Maybe I could intercept the Response object and delete all the HTML?
Any ideas on the best way to do this? It should be pretty easy to code, but I'm trying to understand its design.
user2143356
source share