| Authors: | Robert Forkel |
|---|---|
| Date: | September 12, 2007 |
| Location: | MPDL |
We'll talk about
The web is ...
... the HTTP-speaking part of the internet.
(which mostly speaks HTML, too.)
See also
The Hypertext Transport Protocol
Terms
client (or user agent) requests a response from a server:
GET /index.html HTTP/1.1 host: dev.livingreviews.org HTTP/1.1 200 OK Date: Sat, 01 Sep 2007 14:35:29 GMT Server: Apache Last-Modified: Tue, 03 Apr 2007 08:00:52 GMT ETag: "22c05a-1c89-bc8ed500" Accept-Ranges: bytes Content-Length: 7305 Content-Type: text/html; charset=UTF-8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ... "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> ...
Note: No matter how many layers of abstraction a web applicatio is built on, HTTP is what goes over the wire.
HTTP is standardized in a RFC Unfortunately it shares the fate of (all?) other web standards: many applications only follow the letter but not the spirit of the law. (We'll come to the spirit later, it's called REST.)
Everybody knows:
HTTP is stateless
Why is this good?
Why is it bad?
Is it true?
Example of non-stateless protocol: ftp, e.g. the server has a notion of a current working directory. A tell-tale sign is the LOGOUT (QUIT) command, which is absent in HTTP.
Uniform Resource Locators:
<scheme>://<host><path>?<searchQuery>
The HTTP variety:
http(s)://<host>.<domain><path>?key1=value1&key2=value2#<fragment>
Terms
Notes:
The Content-Types of the Internet:
Multipurpose Internet Mail Extensions Media Types
They specify how to interpret the body.
Top level media types (the stuff before the slash):
For details:
http://www.isi.edu/in-notes/rfc2046.txt
What is REST?
REST is the web app architecture for friends of Leibniz:
HTTP is the best possible protocol for the web.
Short answer: YES!
Longer answer:
User Agents
A web application is
What's the difference between a web service and a web application?
None that I'm aware of.
In the following we take a look at the history of web apps:
The HTTP server
Programming Interface:
The Common Gateway Interface: An API for web applications provided by HTTP servers:
Modern web application frameworks at least provide
but typically also
URL mapping: The mechanism to get from request path to response.
Web server:
request path is a filesystem path, response is the file content.
CGI:
request path is a filesystem path, response created by the script located at this path.
Object publishing:
request path is a path in the web application's object hierarchy.
Configurable:
mapping request path to response handler is completely flexible.
Three options to get from programming language to target format:
A myriad of web application frameworks:
ZOPE, Django, TurboGears, WebWare, web.py, pylons, ...
Because it's so easy to build one in python!
TurboGears is a web app framework subscribing to the Model View Controller paradigm:
TurboGears embraces a best-of-breed philosophy of using/integrating external components.
Skeleton
new-app/ |-- README.txt |-- dev.cfg |-- new_app | |-- config | | `-- app.cfg | |-- controllers.py | |-- json.py | |-- model.py | |-- static | | |-- css | | | `-- style.css | | |-- images | | | |-- favicon.ico | | `-- javascript | |-- templates | | ... | `-- tests | ... |-- new_app.egg-info | ... |-- sample-prod.cfg |-- setup.py `-- start-new_app.py
TurboGears provides a place for
and mechanisms to access all the above conveniently.
In the easiest case, request handling for the programmer means:
What TG does behind the scenes:
Request headers:
Response creation:
set response status code by:
response.status = 200
create response headers by assigning to response.headers, e.g.:
response.headers['Content-Type'] = 'text/plain'
create reponse body by returning the body as string from the controller method.
Client
var getData = function () {
var req = getXMLHttpRequest();
req.open("GET", '/data');
var d = sendXMLHttpRequest(req);
d.addCallback(evalJSONRequest);
d.addCallback(showData);
return false;
}
var showData = function(data) {
document.getElementById('id').innerHTML
= data
}
Server
@expose(template=package.templates.view.kid) @expose(format='json') def data(self, *args, **kwargs): return dict(args=args, kwargs=kwargs)
You want to have FireFox (2.x) and the following extensions: