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:
cons:
Silex
Pros:
Cons:
Which one do you think is the best?
Thanks
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).
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.
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.
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 :)
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() {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With