Building a RESTful PHP Server: Output Handlers

This is the third installment in my series about writing a RESTful web service in PHP (the previous entries are about understanding the request and routing it. It is probably the last one but there are a few other things I’d like to cover such as error handling, so I might keep adding to it, especially if I get any particular requests or interesting questions in the comments. So far we’ve covered parsing requests to determine exactly what the user is asking for, and also looked at routing to a controller to obtain the data or perform the action required. This post gives examples of how to return the data to the client in a good way. Continue reading

PHP 5.4 Built In Webserver

One of the big features arriving with PHP 5.4 is the addition of a built-in basic webserver for use in development environments. Quite a few of the other scripting languages have something like this so I’m very pleased to see it in PHP. Using a server like this makes it easy to quickly try out some scripts without needing to configure apache or really do anything much! I had to look up a few things to get started, so I thought I’d write them down for posterity. Continue reading

Building A RESTful PHP Server: Understanding the Request

Once upon a time, what seems like a lifetime ago, I was away for a couple of weeks, and I wrote a series of posts about serving RESTful APIs from PHP to keep my blog going while I was away. Fast forward a few years and those posts are outdated and still wildly popular – so I thought it was about time I revisited this and showed how I’m writing RESTful PHP servers today!

In the first part of this (probably) 3-part series, we’ll begin with the basics. It might seem boring, but the most important thing to get right with REST is parsing all the various elements of the HTTP request and responding accordingly. I’ve put in code samples from from a small-scale toy project I created to make me think about the steps involved (should I put the code somewhere so you can see it? Let me know). Without further ado, let’s dive in and begin by sending all requests through one bootstrap script: Continue reading

Which Basket Should A Developer Put Their Eggs In?

The situation goes like this. Lots of excellent, capable people have great ideas for new software products. They are bootstrapping their venture, so they look for a developer who wants to give some time up front and receive a fair (let’s assume fair) share of the rewards once the product becomes successful.

The question is: as a developer, how do you know which of these products (I get about one tempting enquiry a month from what sounds like a real person who isn’t building a social network) is a good bet?

Using lrnja.net Custom URL Shortener with Bit.ly

I’m a big bit.ly fan and recently I registered a shorter URL to use for short links – and I went for lrnja.net. I sat down to configure my new domain with bit.ly, and it was very straightforward (I’d almost say “designer-proof”! /me ducks).

  • First: register your domain
  • Log in to your registrar’s control panel and add an A record*
  • That’s it! In about 24 hours, you’ll be able to shorten with your domain

* or a CNAME if you want to use a subdomain of an existing domain.

Bit.ly has excellent instructions here: lrnja.net/bitlydomain

The Tree Command

Today I’m working on a little tutorial (about writing RESTful services, for this site) and I used the tree command to illustrate the file and directory layout of the project. I love this little command and use it frequently, but it isn’t very well known so here’s a quick example. Continue reading

Tracking Your Domain with Bit.ly

As a blogger and lover of graphs, I am not sure how I hadn’t already seen bit.ly’s tracking domain feature. With this, you can register a domain and see reports on all of the URLs that are shortened with bit.ly which point through to that domain.

Continue reading

Inner vs Outer Joins on a Many-To-Many Relationship

Someone will probably tell me that this is an elementary-level topic, but I got some good questions regarding joins from my most recent ZCE class students, so I thought I’d put down the examples that I used to explain this to them. Being able to join with confidence is a key skill, because it means that you can refactor and normalise your data, without worrying about how hard something will be to retrieve.
Continue reading