PHP, .NET, and the REST

2014-10-14 03:46:00 +0000 - Written by Carl Burks

Recently I began to develop a project at home using PHP. In my work life I typically code in the .NET world. With .NET you can have an integrated stack. Windows, IIS, ASP.Net, WebAPI, TypeScript, Visual Studio IDE, MSSql, and TFS.

The landscape changes a bit with other technologies. You don’t really have the Microsoft silo. You can have seemingly infinite combinations of technologies. Operating Systems can range from Windows, Apple, every strain of Linux and other more obscure systems. Web servers you might pick IIS, if you are on windows, or Apache, or Nginx, NodeJs, or any number of other servers. You might code with Perl, PHP, Java… You could use a MySQL, MsSQL, MariaDB, Oracle, MongoDB, Cassandra or any of the plethora of choices. For REST you might be lucky enough to have a language with built in utilities or might have to roll your own. For client script you probably will use JavaScript, but then you’ve got to think about which frameworks you are going to use: Underscore, JQuery, Angular, Knockout. You probably will need a script manager so you can pick something like RequireJS. Not to put too fine a point on it there is a mind boggling amount of technologies available to accomplish the same goal.

Here is what I went with:

Arch Linux (for development in the wild probably pick something a little different)
Apache (using mod_rewrite to achieve the nice URL effect for a web api /api/version/controller)
PHP (Sometimes you like a challenge)
RequireJS* (is planned not implemented yet)

One of the challenges to implementing REST on PHP I encountered was the lack of PUT and DELETE variable support. For GET and POST the global variables $_GET and $_POST are available, but accessing for PUT and DELETE you need to hand roll the support:

        $_delete = [];
         parse_str(file_get_contents(‘php://input’), $_delete);

        $_put = [];
         parse_str(file_get_contents(‘php://input’), $_put);

I’ve been using the Atom editor from GitHub to do most of the coding.

All in all it has been an enjoyable experience.

I will post more info and a link to the source once I get a little further into the project.

-Carl Burks