REST Web Services: Symfony 2 vs silex

We are going to implement a set of REST web services in PHP. For this, we chose 2 frameworks: Symfony 2 and Silex (microarchitecture as a phar archive based on Symfony2).

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

here is a list of the pros and cons i have received so far for these two frameworks

Symfony2

Pros:

  • more powerful
  • Doctrine orm
  • can be debugged using XDebug
  • config in yml
  • more used in the community
  • additional support
  • IDE autocomplete
  • fast

minuses:

  • Does FOSBundle need to do REST (?) (In fact, I would like to know if this is really useful)

Silentx

Pros:

  • easy
  • It seems easier to create a REST url (?)
  • easier to deploy (phar archive)

Minuses:

  • no Doctrine ORM
  • impossible to debug (phar archive)
  • no autocomplete in IDE Configuration
  • must be hard-coded
  • maybe a little slower, as in the phar archive?

Which, in your opinion, is the best?

thanks

+8
rest php symfony silex
source share
2 answers

Personally, I really like symfony 2, it's easy to create a REST URL using annotation 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() { ... } 
+12
source share

Depending on the size of your project, and since you stated that it is quite small, I would choose Silex.

Almost all the flaws you list for Silex are eliminated if you enable silex through the composer . Then it just loads the Silex dependency inside the vendors, and you have no overhead for phar or lack of code completion in your IDE. In fact, the PHAR mailing list is out of date .

As for Doctrine, Silex has a built-in Doctrine ServiceProvider that loads the Doctrine DBAL into a Silex project without any problems. You can easily add DoctrineORM yourself or use one of the third-party service providers found on github.

I am creating a fairly large REST API with Silex and have not regretted one, starting with Silex. You get many advantages of Symfony2 components, since Silex is built with them and has a very lightweight microframe, without having to go through the hours of setting and setting the barley.

And to be honest, I have to admit that I'm not a big fan of annotations, annotations are fine, but I think @mcfedr would be examples, taking it too far, but it's just a personal taste.

I hope I exposed some of the prejudices about Silex. Give him a swing, you won’t regret it. On the other hand, you probably won’t regret Symfony2 :)

+16
source share

All Articles