Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST web services: Symfony 2 vs silex [closed]

We're going to implement a set of REST web services in PHP. We've selected 2 frameworks to do that: Symfony 2 and Silex (micro-framework as a phar archive, based on Symfony2).

For now, there will be only a few services, with a few resources returned as GET, but the set of method will eventually grow and include other rest actions (put/post/delete).

here is the list of pros and cons I've got so far for these 2 frameworks

Symfony2

Pros:

  • more powerful
  • Doctrine ORM
  • can debug with XDebug
  • config in YML
  • more used in the community
  • more support
  • autocompletion in IDE
  • fast

cons:

  • Need FOSBundle to do REST (?) (actually, I'd like to know if this is really useful)

Silex

Pros:

  • lightweight
  • seems easier to create REST urls (?)
  • easier to deploy (phar archive)

Cons:

  • no Doctrine ORM
  • cannot debug (phar archive)
  • no autocompletion in IDE
  • config must be hardcoded
  • may be a bit slower, as it's in a phar archive ?

Which one do you think is the best?

Thanks

like image 414
David Avatar asked Apr 17 '12 11:04

David


People also ask

What makes Silex different from other frameworks?

Silex aims to be: concise (it exposes an intuitive and concise API that is fun to use), extensible (it has an extension system based around the Pimple micro service-container that makes it even easier to tie in third party libraries) and testable (it uses Symfony's HttpKernel, which abstracts request and response and simplifies app testing).

What is a RESTful web service?

REST Services or RESTful web services are built to work best on web. REST (Representational State Transfer) is architectural style in which constraints are specified. If these services are applied to a web service, it can enhance the performance, scalability and modifiability.

What is Silex in PHP?

Silex is a PHP microframework built on the shoulders of Symfony and Pimple and also inspired by Sinatra. A microframework provides the guts for building simple single-file apps.


2 Answers

Depends on the size of your project really and since you stated that it's quite small I would have chose Silex.

Almost all of the cons you list for Silex are ruled out when you include silex through composer. Then it just loads the Silex dependency inside vendors and you don't have the overhead of the phar nor the lack of code completion in your IDE. In fact the PHAR distribution is deprecated.

As for Doctrine, Silex has a built in Doctrine ServiceProvider that seamlessly loads Doctrine DBAL in your Silex project. You can add DoctrineORM easily yourself or use one of the 3rd party serviceProviders found on github.

I'm building a rather big REST API with Silex and haven't regretted a single thing starting off with Silex. You get a lot of the advantages of the Symfony2 components since silex is built with them and have a very lightweight rest-ready microframework without having to go through hours of yaml configuration and setting up.

And to be honest I must admit I'm not a huge fan of the annotations, annotations are fine but I think the examples be @mcfedr take it a little too far but that's just personal taste.

I hope I've debunked some of the prejudices you have about Silex. Give it a swing, you won't regret it. On the other hand, you probably won't regret Symfony2 either :)

like image 99
ChrisR Avatar answered Oct 05 '22 23:10

ChrisR


Personally I really like symfony 2, its easy to create REST urls using the annotations syntax, in your controller you put something like

/**
 * @Route("/user/{id}", requirements={"id" = "\d+"}, defaults={"_format"="json"})
 * @Method({"GET"})
 */
 public function getUser($id) {
     ...
 }
 /**
 * @Route("/user", defaults={"_format"="json"})
 * @Method({"PUT"})
 */
 public function putUser() {
     ...
 }
like image 26
mcfedr Avatar answered Oct 06 '22 01:10

mcfedr