HTTP == HyperText Transfer Protocol
HTTP is the protocol of the web
HTTP is a plain text protocol (as opposed to a binary protocol) that features key-value metadata in the form of headers and sometimes a body
Other protocols:
The components of HTTP are Requests and Responses
How the web gets to you:
In practice, its more complicated than that, as for each page the browser will request CSS, JavaScript, images, and JavaScript on a page may perform asynchrnous requests after page load.
However, each of these is an HTTP request process which is handled the same way.
A simple HTTP request:
telnet 127.0.0.1 80 GET / HTTP/1.1
What this does:
This is the simplest request you can do. Normally, browsers (also called user agents) send headers with the request that specify their capabilities and other metadata about what they're requesting.
HTTP/1.0 200 OK Server: PasteWSGIServer/0.5 Python/2.6.5 Date: Sat, 07 Aug 2010 01:59:59 GMT Content-Type: text/html Accept-Ranges: bytes Last-Modified: Thu, 08 Jul 2010 23:07:29 GMT ETag: 1278630449.7-2870 Content-Range: bytes 0-2869/2870 Content-Length: 2870 <html> <head> <title>Jeff's cryptomythic web page</title> ...
Let's break this down:
since it's OK, you can probably guess that everything is fine here
Then come headers, a (Name: value) pair, one per line, separated with a ':':
Last-Modified and ETag (amongst other headers) are used by browsers with a HEAD request to determine if the page needs to be reloaded
Different servers will return different headers based on the response
User agents (browsers) render the response based on the headers returned
Then comes the body of the response (HTML)
Note: lines are terminated in HTTP by carriage return + linefeed characters (CRLF). This is how windows files are terminated. On linux, there is only the linefeed character
These are things a request can do, also called methods
↑ these are the only types you can do in a form
Some of these (for example, HEAD) are done internally by browsers. They are useful for AJAX requests and for making RESTful web services.
DAV (=Distributed Authoring and Versioning) adds even more verbs to these
The server returns a number indicating the status of the reponse.
The server has a problem with your request
These are just a few of the total codes chosen because they are the most common used.
The 300 series
The most common redirection codes:
When to use what?
How long to persist permanant redirects?
That's a good question! As long as one needs to, and no longer
Example: Accept: text/html,application/xhtml+xml
...etc
http://k0s.org/mozilla/craft/?show_header=Accept,Host,Unicorn&blink=true&black#end
There are several protocols:
Effect of the slash: if a slash is appended to a path (e.g. /mozilla/craft/ vs. /mozilla/craft the browser looks for relative resources under the slash. For this reason, (most) links on http://k0s.org/ append slashes if they are containers (directories).
slash delimeters are purely convention! A web service (or site, for that matter) doesn't have to use them to mean delimination of resources (albeit, doing so builds on existing tools).
The order of the query string doesn't matter, except when entries are duplicates.
The anchor is not accessible to the web server, but is accessible to JavaScript
slashes are used for division
Source: http://k0s.org/hg/webcalc
http://127.0.0.1:5151/8/4
yields
2.0
http://127.0.0.1:5151/80*z*sin%282.*3.14*x%29**y?z=8..10&y=1..4&x=0..0.1..1
yields
x,y,z,result 0.0,1.0,8.0,0.0 0.0,1.0,9.0,0.0 0.0,1.0,10.0,0.0 0.0,2.0,8.0,0.0 0.0,2.0,9.0,0.0 0.0,2.0,10.0,0.0 0.0,3.0,8.0,0.0 0.0,3.0,9.0,0.0 0.0,3.0,10.0,0.0 0.0,4.0,8.0,0.0 0.0,4.0,9.0,0.0 0.0,4.0,10.0,0.0 0.1,1.0,8.0,376.017616457 0.1,1.0,9.0,423.019818514 0.1,1.0,10.0,470.022020571 0.1,2.0,8.0,220.920699822 0.1,2.0,9.0,248.535787299 0.1,2.0,10.0,276.150874777 0.1,3.0,8.0,129.796992145 0.1,3.0,9.0,146.021616163 0.1,3.0,10.0,162.246240182 0.1,4.0,8.0,76.2593056402 0.1,4.0,9.0,85.7917188452 0.1,4.0,10.0,95.3241320503 0.2,1.0,8.0,608.550054724 0.2,1.0,9.0,684.618811565 0.2,1.0,10.0,760.687568405 0.2,2.0,8.0,578.645576726
...
Warning: this code has not been audited for security!
REpresentational State Transfer
Because HTTP is stateless (with the exception of cookies), it makes a great vehicle for writing functional services!
Why is it important to use the right code
How it works:
How a RESTful API would work:
Firstly, it'd be better if it would translate a website for you
A truly RESTful web service would take a POST request with a from and a to field and the body of the request would be the document to be translated. The service would repond with the translated document.
This way, it could be easily interacted with by a computer!