Pre-lab 2.2: Becoming RESTful

Required Reading

We will  quickly go through the following subjects:

  • HTTP protocol.
  • REST principals.
  • Regular expressions.
You can use any programming language to write server application such as C, C++, Python, Perl, PHP..etc. We will learn in the next lab how to launch a script (or binary) from your web server using CGI Apache module (mod_cgi). Whatever language you would like to use for the next lab, try to learn how to parse JSON data before the next lab. We will give some  examples in PHP, so if you decide to proceed  development with PHP,  please follow installation steps in this pre-lab.

 

HTTP Protocol

Quickly skim this nice tutorial, HTTP Made Really Easy.

REST

If you didn’t get it from android pre-lab 1.3, don’t worry, just continue reading this section, otherwise you may skip.

REST is about using the true potential of HTTP. The protocol is oriented around verbs and resources. The two verbs in mainstream usage is GET and POST, which I think everyone will recognize. However, the HTTP standard defines several other such as PUT and DELETE. These verbs are then applied to resources.

For example. Let’s imagine that we have a user database that is managed by an web service. Using the non-restful approach it would probably look something like this:

A restful application would probably expose an API with a single base resource.

If you want to create a new user you simply send a POST request to that URL with the data you want to create. If you want to retrieve a user you send a GET request to /user/xxx. If you want to update a user you simply send the fields you want to update using a PUT request to /user/xxx. If you want to delete it, you send a DELETE request instead.
An even more concrete example. In a RESTful application you’ll never modify data using a GET request. This is what PUT, POST and DELETE are for. Most web applications do this all the time, though, and are therefore not RESTful.

There’s also an article called How I explained REST to my wife.

Regular Expressions (Regex)

Follow this tutorial, Perl Regular Expressions. You don’t have to learn Perl in order to use Perl regex; however, Perl Regular Expression is used in many different systems and applications such as Apache (mod_rewrite), vim, sed command..etc.

Reference