Reputation: 919
I am developing web application using Symfony2. Methods in Controller will be called from Web Application but at the same time I need to expose rest api for same functionality. For example Login and get data for a user.
Can one method be configured/written to server the same purpose.
Upvotes: 1
Views: 264
Reputation: 291
Yes, you need to determine the format of your response (HTML, JSON) from the controller(s), based on a parameter from the request. Have a look at the official Routing documentation: http://symfony.com/doc/current/book/routing.html#book-routing-format-param
Now when it comes to REST applications, FOSRestBundle makes things very easy for you. It allows you to configure format agnostic controllers in bunch. This is well documented in their "The View Layer" section.
Upvotes: 1