Pre-lab 2.2: Becoming RESTful
We will quickly go through the following subjects:
- HTTP protocol.
- REST principals.
- Regular expressions.
Quickly skim this nice tutorial, HTTP Made Really Easy.
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:
; html-script: false ]/user_create
A restful application would probably expose an API with a single base resource.
; html-script: false ]/user
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.