Throughout my career as a programmer I’ve had moments that I call “why the hell didn’t I see that earlier” moments when it comes to embracing new technologies and techniques. The first such moment was when I discovered frameworks. I mean, how many times did I write PHP apps with page and/or front controllers. And all that mixing of business logic and display logic. It was madness!
The next such time was when my friend Kevin convinced me to throw away my GUI shackles and learn to use the One True Editor. Given how often the advanced features of the never-ending parade of IDE’s I used were not being used, vim turned out to be exactly the tool I needed.
Well folks, I’ve had another one of these moments. What is it? Repeat after me: THOU SHALL BUILD YOUR APPLICATION AS AN API FIRST, AND FRONT END SECOND. I’ve been toying with this idea for a while, but a recent side project and these three awesome articles finally convinced me that my instincts were right, and that the extra work involved with API-first development (wow, maybe I’ve coined a new term) pays off in our new world of multiple devices wanting to slurp up online content.
So, here are two tools that I think my readers should know about. For those working with PHP, I cannot recommend enough the use of FRAPI if you have a legacy application that you need to provide an API for. Now, I will admit that the installation procedure is not for the faint-of-heart (you have to install packages via PEAR, PECL, and perhaps even adding packages for your operating system) but once you have it installed, you now have a tool to allow you to quickly create an API.
In a nutshell, FRAPI is a framework for creating a REST API. Using the admin panel, you define the URL’s you want for your API and it generates some code for you. Then you edit the generated code to provide the actual output from your API, and reaction based on your GET/POST/PUT/DELETE request. From when I downloaded it, it took me about 30 minutes to get FRAPI installed and create my first API call, including a customized output template.
The documentation via the wiki isn’t that great, but it gives you everything you really need to get started. Kudos to the boys at echolibre for creating a super-useful tool.
The documentation for django-tastypie is good, and this article on JS on the front, scripting language on the back shows you a practical use for it.
So don’t be afraid to build your application from the API out, now that there are plenty of tools to allow for easy integration with your application.