What php framework is best suited for a scalable rest api-service?
One that is minimal. I am about to look at slim framework to compare it against my PHPRouter (don't use my router for production yet). You don't need something like Zend or CodeIgnitor that adds a bunch of layers you don't need (mvc for example)
There isn't really any reason why you couldn't use the complete [Symfony 2 stack or cherry pick specific [url=http://symfony.com/doc/current/components/index.html]components](http://symfony.com/) like the router for a such a task. I guess it would partially depend on the business purpose of the API. Using Symfony/components any loss in performance you will make up in maintainability, support, dependability, scale, and general code quality.
I'm always skeptical of projects that compare themselves to others on the basis of performance. Judging performance is bias unless the two applications/code bases do the same same exact thing meeting all the business requirements of a specific project. Though performance comparisons always tends to be based on the simplest business requirements that would rarely if ever fulfill the needs of a real-world project in continuous development.
To that end I recommend maintainability, support, and code quality as the driving factors behind choosing a framework, cms, or any other open rather than performance. Unless the business requirements are very out of the ordinary the major performance bottlenecks will always be interacting with other services. Attempts to add micro-optimizations in other places tend to be a waste of time and offset by future changes. You are better off implementing caching strategies when problems arise than micro-optimizing especially when it comes to software that is in continuous development.
That is why I would recommend a framework like Symfony or to cherry pick components as opposed to using some random project by a single individual that will most likely be abandoned all to soon because they move onto the "next big thing". With large projects like Symfony there is a very slim chance the project will be dropped. There is a high chance certain versions will not be supported in distant future. However, death of versions naturally happens in the open source life cycle.
IMO, code quality can degrade when you try to cram a REST API into an existing MVC framework. A REST API doesn't need a view, view helpers or most other features that comes with it. Most APIs will be performing a simple task of connecting to a DB and running some sort of operation, and return that result. This can be achieved with so much less code and overhead. Developing without a framework shouldn't be viewed as a scray thing, nor should it be viewed as a bad thing as long as you still use good design practices (and this does not mean what is commonly viewed as PHP's good design practices)
I agree, that code quality can degrade when you try to develop a REST API with a MVC framework. But lightweight is not the most important requirement for me.
Is there any mature php rest api framework with includes all important api functionality (authentication, caching, etc)?
What type of authentication are you looking for?
I must admit, that I have not decided yet on authentication method
It's probably worth mentioning that Symfony2 that oddz recommended earlier doesn't identify itself as an MVC framework. It's a Request/Response framework, and it doesn't force you to cram your code in any way you don't like. You can use a view layer or not; it's optional. You can use an ORM or not; it's optional. You also get built-in authentication (using whatever method you like... basic http, html forms, via Twitter, whatever), built-in caching, built-in validation, among lots more. It's also testable, it encourages writing DRY code, it has a large community, so on and so forth.
I'm getting the impression that MVC is being equated with something resource-intensive or only for "complex" apps.. Surely, even when building something as "simple" as a REST API you'd want to maintain a basic separation of concerns? Even APIs grow, and the requirements change.. and it's still going to be easier to maintain if you don't have persistence logic mixed in with display logic, right?
Very good point! Times like this I wish SitePoint had an upvote feature.
MVC its self really isn't all that resource intensive, its what usually comes with it. Certain small operations / tweaks to get the request ready. When dealing with a REST API, for me anyway, small increases in page load time is a huge deal. If I can get another 3 requests in per second, when running a client that is making 30 simmultanous calls to the API at a time, you now have a gain of almost 100 requests a second.
You'd be suprised how easy it is to keep an API project clean without "seperation", which I'm assuming you mean the model and controller. Your seperation comes from one class per file.
You can also look into [apigility which gives you a GUI to create an API. Its built on top of Zend Framework 2 & made by Zend. If you're looking at micro-frameworks then take a look at [URL="http://silex.sensiolabs.org/"]Silex](http://www.apigility.org/) as well, it has been built using Symfony components by the makers of Symfony framework.
ZF2 has done horribly in many benchmarks. Like, really bad. I wonder if apigility strips any of it out.
I usually take most benchmarks with more than a pinch of salt as barring few exceptions (where the reviewer or the person benchmarking the frameworks know well enough about all or most of them) all benchmarks done are with "Hello World" skeleton apps which present a very skewed picture. I mean its common sense that in such a benchmark a micro framework would score better than almost all full stack frameworks, heck, a simple PHP file with just "echo 'Hello World';" would score best.
I agree ZF2 doesn't have much of a stellar reputation. I'm not sure if they've improved anything in apigility or removed unnecessary stuff. I've just played with it for a very short while, someone at work mentioned it to me so I installed it to see whats it about. But the idea is quite intriguing, an app which lets you make APIs quickly, definitely worth checking out in detail.
Hello World get's you the base overhead of the framework. I've seen several benches done against more ocmmon frameworks (ZF1, ZF2, CI, etc) and ZF2 was at the bottom. If I remember correctly, ZF2 was somewhere around 5 to 10 times slower than ZF1.
Absolutely. Every API doesn't have to have great performance.
If you are concerned about performance and are in a dedicated hosting environment perhaps this would be a great opportunity to check of Phalcon. I haven't used it myself but nothing is going to be faster than a php extension itself. Not to mention having looked over the docs I'm quite impressed. It seems like they have taken all the good parts of popular frameworks like Symfony and bundled them into a PHP extension. Also, the documentation looks pretty thorough. The framework also has a concept of a "Mini" application which would be perfect for something like a RESTful API without a client-side front-end. I recommend checking it out if possible, I surely would try it out in a project if given the opportunity.
Phalcon looks cool. Has anyone used it for building a REST-ful API? (I have searched on github without any luck)
This topic is now closed. New replies are no longer allowed.