8

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?

3
  • Have you found a solution for this? I would be interested. Commented Feb 5, 2013 at 21:19
  • Actually I did. I ended going with having the website be another client and requesting data from the platform through http requests. I'm using guzzle (with my own GuzzleBundle for symfony2) to make the requests and automatically deserialize the JSON responses into entities. On the web side I actually have duplicated entities but without any doctrine mappings, and in some cases the actual data ended being different between the actual business entity in the backend than the data needed for the front end. If it's of any use to you my guzzle bundle is at github.com/xamado/guzzle-bundle Commented Feb 6, 2013 at 18:41
  • Thanks! So you actually have two requests for each request on your website? This is something I'd like to avoid.. Commented Feb 6, 2013 at 20:45

2 Answers 2

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Guess I forgot to mention that I intended the website itself to also be a symfony2 project, that's where my question comes into play regarding how to handle a symfony2 website where it's entities actually come from a REST api and not, let's say, doctrine.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.