HTTP protocol HTTP, circa 1989 a resource «give me the HTML representation of thatresource» «ok, here» Client request GET /hello.txt Server response Hello, world! Client Server Http 1.1 Request line Client request Server response GET /hello.txt HTTP/1.1 Start line HTTP/1.1 200 OK GET /foo/bar.html HTTP/1.1 Host: www.example.com Headers body Content-type: text/plain <empty line> Hello, world! the method the resource the format protocol Marco Tarini, Uninsubria 1
GET /books/list.html HTTP/1.1 Host: localhost:3001 User-Agent: Mozilla/5.0 (Intel Mac OS X; en-us; rv:1.8.0.7) Gecko Accept: text/xml,application/xml,text/html;q=0.9,*/* Accept-Language: en-us,en Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8 $ GET /index.html HTTP/1.1 HTTP/1.1 301 Moved Permanently Date: Mon, 06 Dec 2010 17:19:49 GMT Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14. Location: http://localhost/manual/ Content-Length: 232 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>moved Permanently</h1> <p>the document has moved <a href="http://localhost/manual/">here</a>.</p> </body></html> REQUEST LINE (by client) $ GET /index.html HTTP/1.1 HTTP/1.1 301 Moved Permanently Date: Mon, 06 Dec 2010 17:19:49 GMT Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14. Location: http://localhost/manual/ HEADER Content-Length: 232 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> BODY </head><body> <h1>moved Permanently</h1> (the resource) <p>the document has moved <a href="http://localhost/manual/">here</a>.</p> </body></html> $ GET /index.html HTTP/1.1 HTTP/1.1 301 Moved Permanently Date: Mon, 06 Dec 2010 17:19:49 GMT Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14. Location: http://localhost/manual/ Content-Length: 232 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>moved Permanently</h1> <p>the document has moved <a href="http://localhost/manual/">here</a>.</p> </body></html> Marco Tarini, Uninsubria 2
Status codes Redirections 2xx 3xx 4xx 5xx success redirection client error server error 301 Moved Permanently 302 Found 303 See Other Examples 200 OK 301 Moved Permanently 410 Unauthorized 404 Not Found 500 Internal Server Error REQUEST LINE (by client) $ GET /index.html HTTP/1.1 HTTP/1.1 301 Moved Permanently Date: Mon, 06 Dec 2010 17:19:49 GMT Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14. Location: http://localhost/manual/ HEADER Content-Length: 232 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> BODY <title>301 Moved Permanently</title> </head><body> A common example: <h1>moved Permanently</h1> <p>the document a HTML has moved document <a href="http://localhost/manual/">here</a>.</p> </body></html> Marco Tarini, Uninsubria 3
HTML documents A web page is a HTML document Consists of text (what you see) markup (what it looks like) references to other resources (e.g. images of videos) links to other pages hyper-links functionality e.g. scripts World Wide Web the Web, WWW A collection of documents in HTML and other resources images, multimedia, videos located by URL interlinked (for the most part) the World Wide Web A Web-Site: a collection of related web-pages World Wide Web: a collection of Web-Sites billions of them! and counting (fast!) plus, the deep web What is a resource? A resource can be anything that has identity. Familiar examples include an electronic document, an image, a service (e.g., today's weather report for Los Angeles ), and a collection of other resources. Most familiar example of a resource: a file sitting on a web server (an image, an hypertext, a movie, a text ). Marco Tarini, Uninsubria 4
HTTP protocol Examples of resources «give me the HTML representation of thatresource» a resource Version 22.1 of a (desktop) application http://example.com/software/releases/22.1.tgz The most recent version of a (desktop) application. http://example.com/software/releases/latest.tgz Client «ok, here» Server The articles of 2 October 2007 of a blog http://example.com/blog/2007/10/2 An article about RESTful Web Services http://example.com/blog/restful-web-services URI URI examples Uniform Resource Identifiers (URI) provide a simpleand extensiblemeans for identifyinga resource. ftp://ftp.is.co.za/rfc/rfc1808.txt gopher://spinaltap.micro.umn.edu/00/weather/california/los%20angeles http://www.math.uio.no/faq/compression-faq/part1.html mailto:mduerst@ifi.unizh.ch news:comp.infosystems.www.servers.unix telnet://melvyl.ucop.edu Marco Tarini, Uninsubria 5
URI vs URL URI examples URI: Uniform Resource Identifier URL: Uniform Resource Locator URL refers to the subset of URI that identify resources via a their network location <scheme>:<scheme-specific-part> mailto:marco.tarini@uninsubria.it http://www.example.com/pages/hello.txt telnet://192.0.2.16:80/ news:rec.arts.int-fiction http URL http URL http://<host><path> http://www.example.com/ scheme: http host: www.example.com path: / http://<host><path> http://www.example.com/books/list.html scheme: http host: www.example.com path:/books/list.html Marco Tarini, Uninsubria 6
http uri http URL http://<host><path>[<query>] http://www.google.com/search?q=facoceri&start=10 scheme: http host: www.google.com path: /search query string: q=facoceri&start=10 http://<host><path>[<query>][<fragment>] http://www.google.com/search?q=facoceri&start=10#fragm scheme: http host: www.google.com path: /search query string: q=facoceri&start=10 fragment: fragm Http methods Safe methods GET Get a resource from the server. POST Send data to the server for processing. HEAD Get just the headers PUT Upload resource DELETE Remove a document OPTIONS Ask what methods are available. A method is safewhen it has no visible effect on the status of the app Marco Tarini, Uninsubria 7
GET vs. POST GET vs POST GET safe POST not safe Get: useful to readinfo Post: useful to modify info bookmarkable parameters in URL not bookmarkable parameters in BODY Web Applications A web application is basically a refurbished Web Page / Web Site with functionalities Distributed Application Architecture Client Server Database Back End But, behind the scenes Marco Tarini, Uninsubria 8
Web Application Architecture Back End Web Application Architecture Back End (any) Browser internet Server LAN Database HTTP LAN Client Web Server / Application Server Client Web Server / Application Server DataBase Apps Desktop Applications Web Applications Mobile Applications Mobile Web Applications Risoluzione di un URL http://www.uninsubria.it/home.html 1.Ask to the DNS the IP address of www.uninsubria.it 2. Connect with TCP to port 80 of 193.206.179.151 3. Send GET /home.html HTTP/1.1 4. Receive the document home.html 5.Display it on screen Marco Tarini, Uninsubria 9
Stateless http://www.google.com/search?q=facoceri&start=15 Esempionon-stateless: ftp $ ftp ftp.funet.fi Connected to ftp.funet.fi. 331-Welcome to the FUNET anonymous ftp archive Password: Using binary mode to transfer files. ftp> cd pub 250 OK. Current directory is /pub ftp> get README local: README remote: README 226-File successfully transferred ftp> quit 221-Goodbye. You uploaded 0 and downloaded 18 kbytes. 221 Logout. $ Addressability A Web Application is addressable if it exposes its relevant data as resources Marco Tarini, Uninsubria 10
Google Mail è indirizzabile? https://mail.google.com/mail/#inbox/11dbe2460af15fe6 https://mail.google.com/mail/#label/aaa-agire https://mail.google.com/mail/#search/marco $ GET /index.html HTTP/1.1 HTTP/1.1 301 Moved Permanently Date: Mon, 06 Dec 2010 17:19:49 GMT Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14. Location: http://localhost/manual/ Content-Length: 232 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>moved Permanently</h1> <p>the document has moved <a href="http://localhost/manual/">here</a>.</p> </body></html> MIME types text/plain text/html image/gif image/jpeg <primary type>/<subtype> application/pdf Mime types text/html; charset=utf-8 <primary type>/<subtype>; <parameters> Marco Tarini, Uninsubria 11