I have to build a RESTful API for Fastaval.
The purpose is to tie together three different tools, two of which are
built by ourselves (but different developers) and one of which is
Wordpress. Instead of trying to roll everything into one codebase the
solution I'm opting for is adding a mediator service in the middle. And
for that I'll use a PHP RESTful framework. So the question was, which
one to use.
I had a quick look at the scene and came up with the following
There are others as well, but these looked like the best candidates for
quickly setting up a small API.
My needs for the framework are:
- small size
- get out of the way
- don't force me to do more stuff than I need
- few requirements
- ability to get into it in 5-10 minutes
This framework seems nicely done. However, after looking at the source
and the setup for 5 minutes, I found more overhead than I want.
Specifically, the process of dispatching from request to controller
involved much more code than I think should be needed. On top of that,
it seems to include Smarty, which is 100% overkill for my needs (and
which I'm generally opposed to). And as a final hint that I wouldn't
like the framework, it included a module for doing basic http
authentication. Not exactly something I want in my RESTful API.
Here there's very little setup needed before you're running a RESTful
service. The framework really does all it can to get out of the way, so
after looking for 2 minutes at the included example index file you'll
know how to get the basics going. The size of the framework is about
230K, which is not bad. Overall a very good contestant.
After installing this and setting it up, I browse to the test page only
to find it needs a database to work. Instant dismissal: if my API
doesn't need a database I'm sure as hell not going to be bothered with
creating one for the framework.
This is the second final contestant for the framework to use. Again,
fairly simple setup and you'll know very fast after installing it how it
works, so you won't waste a lot of time reading docs before you can
begin to use it. I like it a bit less than Slim, though, as it seems to
need more manual setup (more static calls than I would expect, before
things are running). However, very small size (80K), nice set of
libraries, a nice surprise in terms of flexibility, so this one is
definitely not out of the race.
This seems like a nice a fairly advanced framework, however, right out
of the box it involves too much complexity to be of any use to me. First
off, I need to setup two virtualhosts for it, one for the frontend and
one for the backend. I don't need that, as I don't need a backend.
Secondly, I couldn't even get to the point of figuring out if Frapi
needs a backend, as it wouldn't run without APC which I don't have
running on my small netbook. So it got disqualified from the race right
there. If it hadn't, it would have been on account of size, as it packs
in 31MB just in libraries.
I'll probably go with Slim though I'll try to do a minimal test-case of
Slim and Epiphany (just with an auth module) to compare developing with
both. I'm sure the other frameworks have positive sides as well, but
they strike me as overkill for a RESTful API. I get why you would want
to make things slightly more complex if the goal is developing web
applications (as Tonic is advertised for, for instance) but including
smarty? That's simply unnecessary bloat to me.
One thing I skipped over here is obviously the existing bigger
frameworks like CodeIgniter, CakePHP, Zend, etc. All these are way
overkill for an API, if you ask me. They don't get out of the way,
instead they dictate most of your choices (not necessarily a bad thing -
enforcing best practices is good in my book - just not needed here).
Zend, for instance, has a good set of modules that could come in quite
handy for a RESTful api (likely why Frapi includes a whole lot of Zend
code), but Zend seems to be built upon the idea that Java development
practices are good and can/should be used in PHP. Which is quite simply
wrong, if you ask me.
So yeah, the proper tool for the job, which in this case amounts to Slim
or Epiphany. Hereby recommended.