Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 website and RESTful API

I'm currently developing a web application, that relies heavily on mobile and desktop clients consulting the web server for information. This can be accomplished nicely making a RESTful API available to handle this. So my idea is to have an application acting as the "platform" which handles all the real business logic and database information behind the curtains.

My plan is to make the platform using symfony2 and OAuth 2.0 authentication mechanisms, combined with RESTful web services.

Now my real dilema comes on the website component. Ideally I would like to think of the website as yet another client that asks this REST platform for information, and completely separate it from the platform itself.

To make it a little bit more clear, let's say we are making a blog with this architecture, so one would have a "platform/backend" that provides a rest service to list articles, for example: /articles/5. This on the backend, and with symfony2/doctrine means that the app has an Article model class, and these can be requested from the DB. A simple controller queries for the Article number 5 and returns all the information in JSON format.

Now the website on this example, could just do the easy thing and also have an Article entity and just query the database directly, but I think it would be cleaner if it could just talk to the platform through it's REST api and use that information as a "backend" for the entities.

So the real question would be, is there anyway to support this kind of design using symfony2? Have entities rely on a REST api for CRUD operations? Or I'm just better off making the platform/website a single thing and share a "CoreBundle" with all the generic entities?

like image 643
Xavier Avatar asked Sep 27 '12 19:09

Xavier


2 Answers

There is nothing in Symfony that prevents you from doing you want.

On the client side you could use Backbone.js or Spine.js.

like image 65
Elnur Abdurrakhimov Avatar answered Oct 06 '22 10:10

Elnur Abdurrakhimov


Have a look at FosRestBundle, it makes your life much easier to create api: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/index.md

like image 23
shacharsol Avatar answered Oct 06 '22 09:10

shacharsol