Bads123
Bads123

Reputation: 919

Can one method in Symfony Controller take care of Rest and Web Request

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

Answers (1)

PapyDanone
PapyDanone

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

Related Questions