HTTP & REST Noah Mendelsohn Tufts University Web: COMP 150-IDS: Internet Scale.

Slides:



Advertisements
Similar presentations
REST Vs. SOAP.
Advertisements

HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
How the web works: HTTP and CGI explained
HTTP Presented By: Holly Mortinson Amy Drout Kyle Balmer & Matt Conklin.
Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July.
Definitions, Definitions, Definitions Lead to Understanding.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Hypertext Transport Protocol CS Dick Steflik.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.
Web Architecture Dr. Frank McCown Intro to Web Science Harding University This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
2: Application Layer1 CS 4244: Internet Software Development Dr. Eli Tilevich.
Rensselaer Polytechnic Institute Shivkumar Kalvanaraman, Biplab Sikdar 1 The Web: the http protocol http: hypertext transfer protocol Web’s application.
1 Chapter 2 & Chapter 4 §Browsers. 2 Terms §Software §Program §Application.
Web Architecture & Services (2) Representational State Transfer (REST)
REST.  REST is an acronym standing for Representational State Transfer  A software architecture style for building scalable web services  Typically,
Wyatt Pearsall November  HyperText Transfer Protocol.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
Versioning, Extensibility & Postel’s Law Noah Mendelsohn Tufts University Web:
Copyright 2012 & 2015 – Noah Mendelsohn Introduction to: The Architecture of the World Wide Web Noah Mendelsohn Tufts University
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
1 Seminar on Service Oriented Architecture Principles of REST.
World Wide Web “WWW”, "Web" or "W3". World Wide Web “WWW”, "Web" or "W3"
2007cs Servers on the Web. The World-Wide Web 2007 cs CSS JS HTML Server Browser JS CSS HTML Transfer of resources using HTTP.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Web Technologies Lecture 1 The Internet and HTTP.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
EE 122: Lecture 21 (HyperText Transfer Protocol - HTTP) Ion Stoica Nov 20, 2001 (*)
RESTful Web Services What is RESTful?
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Overview of Servlets and JSP
JavaScript and Ajax (Internet Background) Week 1 Web site:
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
Week 11: Application Layer 1 Web and HTTP r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Web page consists.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
Intro to REST Joe Gregorio Google. REST is an Architectural Style.
National College of Science & Information Technology.
COMP 150-IDS: Internet Scale Distributed Systems (Spring 2017)
WWW and HTTP King Fahd University of Petroleum & Minerals
HTTP – An overview.
JavaScript and Ajax (Internet Background)
Introduction to: The Architecture of the World Wide Web
COMP2322 Lab 2 HTTP Steven Lee Feb. 8, 2017.
Hypertext Transport Protocol
Introduction to: The Architecture of the World Wide Web
WEB API.
Introduction to: The Architecture of the World Wide Web
COMP 150-IDS: Internet Scale Distributed Systems (Spring 2016)
EE 122: HyperText Transfer Protocol (HTTP)
Chengyu Sun California State University, Los Angeles
Presentation transcript:

HTTP & REST Noah Mendelsohn Tufts University Web: COMP 150-IDS: Internet Scale Distributed Systems (Spring 2015) Copyright 2012, 2103 & 2015

© 2010 Noah Mendelsohn Architecting a universal Web  Identification: URIs  Interaction: HTTP  Data formats: HTML, JPEG, GIF, etc.

© 2010 Noah Mendelsohn 3 Goals  Learn why traditional architectures would not have worked for the Web  Learn the basics of HTTP (review)  Explore some interesting characteristics of HTTP  Learn the REST distributed computing architecture

© 2010 Noah Mendelsohn Question: What would happen if we built the Web from RPC?

© 2010 Noah Mendelsohn Why not use RPC for the Web?  No uniform interface –You’d need an interface definition to follow a link  No global naming  Most RPC data types poorly tuned for documents –Int, float, struct not HTML, XML, mixed-content, etc. We’ll revisit the RPC/Web question later and add some more

© 2010 Noah Mendelsohn HTTP in Action (review from first week)

© 2010 Noah Mendelsohn What Happens When We Browse a Web Page?

© 2010 Noah Mendelsohn The user clicks on a link URI is

© 2010 Noah Mendelsohn The http “scheme” tells client to send HTTP GET msg HTTP GET URI is

© 2010 Noah Mendelsohn The server is identified by DNS name in the URI HTTP GET Host: webarch.noahdemo.com URI is

© 2010 Noah Mendelsohn HTTP GET Host: webarch.noahdemo.com GET /demo1/test.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is demo1/test.html The client sends an HTTP GET

© 2010 Noah Mendelsohn HTTP GET Host: webarch.noahdemo.com GET /demo1/test.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is demo1/test.html The client sends an HTTP GET Note that HTTP is a text-based protocol …but it can carry binary entity bodies such as image/jpeg

© 2010 Noah Mendelsohn The server sends an HTTP Response HTTP GET HTTP RESPONSE Host: webarch.noahdemo.com demo1/test.html HTTP/ OK Date: Tue, 28 Aug :49:33 GMT Server: Apache Transfer-Encoding: chunked Content-Type: text/html Demo #1 A very simple Web page HTTP Status Code 200 Means Success!

© 2010 Noah Mendelsohn The server sends an HTTP Response HTTP GET HTTP RESPONSE Host: webarch.noahdemo.com demo1/test.html HTTP/ OK Date: Tue, 28 Aug :49:33 GMT Server: Apache Transfer-Encoding: chunked Content-Type: text/html Demo #1 A very simple Web page The “representation” returned is an HTML document

© 2010 Noah Mendelsohn Host: webarch.noahdemo.com demo1/test.html The server sends an HTTP Response HTTP GET HTTP RESPONSE HTTP/ OK Date: Tue, 28 Aug :49:33 GMT Server: Apache Transfer-Encoding: chunked Content-Type: text/html Demo #1 A very simple Web page The HTML for the page.

© 2010 Noah Mendelsohn HTTP Methods, Headers & Extensibility

© 2010 Noah Mendelsohn HTTP Requests always have a method HTTP REQUEST Host: webarch.noahdemo.com GET /demo1.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is GET

© 2010 Noah Mendelsohn HTTP Headers GET /demo1.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us Request headers HTTP/ OK Date: Tue, 28 Aug :49:33 GMT Server: Apache Transfer-Encoding: chunked Content-Type: text/html Demo #1 A very simple Web page Response headers

© 2010 Noah Mendelsohn HTTP Extension Points  HTTP –New headers (quite common) –New methods (rare) –New versions of HTTP itself (e.g. HTTP 1.1) (very rare) –New status codes (very rare)  Technologies used by HTTP –Media types (text/html, image/jpec, application/…something new?... –Languages (e.g. en-us) –Transfer encodings (e.g. gzip)

© 2010 Noah Mendelsohn HTTP Protocol for a Discoverable Web

© 2010 Noah Mendelsohn HTTP: the protocol for a discoverable Web  HTTP provides a uniform interface to all resources  You don’t have to know in advance what a resource is like to access it with HTTP…so, you or your software can explore the Web in ad-hoc ways  Self-describing: when a response comes back, you can figure out what it means  Using HTTP to access a resource doesn’t damage the resource  For all this to work, you must use HTTP…and you must use it properly!

© 2010 Noah Mendelsohn HTTP Requests always have a method HTTP REQUEST Host: webarch.noahdemo.com GET /demo1.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is GET

© 2010 Noah Mendelsohn HTTP Methods MethodMeaning GET Retrieve a representation of the resource but do not change anything! POST Update the resource or a dependent resource base on supplied representation HEAD Optimized GET – retrieves only headers, used for checking caches, etc. PUT Create or completely replace the resource base on supplied representation DELETE Delete the resource identified by the URI GET is very carefully defined to make the Web scalable and discoverable.

© 2010 Noah Mendelsohn HTTP Methods MethodMeaning GET Retrieve a representation of the resource but do not change anything! POST Update the resource or a dependent resource base on supplied representation HEAD Optimized GET – retrieves only headers, used for checking caches, etc. PUT Create or completely replace the resource base on supplied representation DELETE Delete the resource identified by the URI GET is very carefully defined to make the Web scalable and discoverable.

© 2010 Noah Mendelsohn HTTP GET Has A Very Particular Meaning HTTP GET Host: webarch.noahdemo.com GET /demo1.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is GET It’s always safe to try a GET on any URI. In fact, that’s why search engines like Google can safely crawl the Web!

© 2010 Noah Mendelsohn It’s always safe to try a GET on any URI. In fact, that’s why search engines like Google can safely crawl the Web! But GET is so convenient that some people use it in the wrong places…if you’re changing the state of a resource you must use PUT or POST! HTTP GET Has A Very Particular Meaning

© 2010 Noah Mendelsohn Demonstration #3:

© 2010 Noah Mendelsohn Using HTTP Properly  If GET is used instead of POST, your applications may update accidentally  If too many applications misuse GET, then it will become impossible to explore the web –If you click a link, you might break something..you would have to ask about each link before clicking! –Search crawlers couldn’t be used…there would be no Google! Read TAG Finding “URIs, Addressability, and the use of HTTP GET and POST”

© 2010 Noah Mendelsohn Web Interaction: Highlights  HTTP: a uniform way to interact with resources  Promotes interoperability & discoverablility  Use HTTP properly: GET is special!  HTTP has features like content negotiation and headers that let you adapt content for your users

© 2010 Noah Mendelsohn The Self-Describing Web

© 2010 Noah Mendelsohn The Self-Describing Web  Everything you need to understand a response is in the response…  …to find the instructions, read RFC 3989…  …and follow your nose!

© 2010 Noah Mendelsohn Follow your nose  The Web community’s term for:  Going step by step through a Web response and the pertinent specifications…  …to figure out what the response means  All the specifications you need are found (transitively) from RFC 3986!  Thus there is a quite rigorous sense in which the Web is browsable and explorable Read TAG Finding “The Self-Describing Web”

© 2010 Noah Mendelsohn The server sends an HTTP Response HTTP GET HTTP RESPONSE Host: webarch.noahdemo.com demo1/test.html HTTP/ OK Date: Tue, 28 Aug :49:33 GMT Server: Apache Transfer-Encoding: chunked Content-Type: text/html Demo #1 A very simple Web page The “representation” returned is an HTML document

© 2010 Noah Mendelsohn Stateful and Stateless Protocols

© 2010 Noah Mendelsohn Stateful and Stateless Protocols  Stateful: server knows which step (state) has been reached  Stateless: –Client remembers the state, sends to server each time –Server processes each request independently  Can vary with level –Many systems like Web run stateless protocols (e.g. HTTP) over streams…at the packet level, TCP streams are stateful –HTTP itself is mostly stateless, but many HTTP requests (typically POSTs) update persistent state at the server

© 2010 Noah Mendelsohn Advantages of stateless protocols  Protocol usually simpler  Server processes each request independently  Load balancing and restart easier  Typically easier to scale and make fault-tolerant  Visibility: individual requests more self-describing

© 2010 Noah Mendelsohn Advantages of stateful protocols  Individual messages carry less data  Server does not have to re-establish context each time  There’s usually some changing state at the server at some level, except for completely static publishing systems

© 2010 Noah Mendelsohn HTTP is Stateless (usually)  HTTP is fundamentally stateless…response determined entirely from GET request & URI –(unless resource itself changes!!)  In practice: –Cookies stored in browser tied to session state and login status –OK: determine access rights from cookie –NOT OK: return different content based on cookie –WHY?: On the Web, we identify with URIs, not cookies!  Of course, the state of resources does change: –E.g. when we add something to a shopping cart 38

© 2010 Noah Mendelsohn REST

© 2010 Noah Mendelsohn REST – REpresenational State Transfer  What is REST? –A distributed system architecture –In practice: implemented using HTTP  Key features –States transferred using representations (HTTP requests/responses) –Server is stateless –URIs (and request data if provided) convey state to application  History –Described by Roy Fielding in his PhD thesis –Came after Tim BL invented the Web, but… –…Roy was very influential in development of formal specifications of and details of HTTP and URIs Fielding’s PhD Thesis:

© 2010 Noah Mendelsohn Building a REST application  All data communicated using HTTP GET / POST –Unit of interaction is document –Formats like JSON, XML, RDF, N3 used to convey data  State of navigation typically captured in URIs: –URI to start application –URI for 2 nd step –URI for 3 rd step –Captures client parameters & input in URIs (e.g. search parms, flight numbers)  States of a REST application are linkable, bookmarkable  Examples: – –Google search –Google maps (AJAX example: uses REST recursively)

© 2010 Noah Mendelsohn A Complex REST Application Google Maps Warning: some details of Google’s implementation may have changed since this presentation was prepared

© 2010 Noah Mendelsohn AJAX Application – Google Maps Images retrieved in segments using ordinary Web HTTP Requests

© 2010 Noah Mendelsohn AJAX Application – Google Maps JavaScript at client tracks mouse and moves images for smooth panning… asynchronously requests new image tiles in background

© 2010 Noah Mendelsohn AJAX Application – Google Maps The Web is used to retrieve an ordinary file listing points of interest…. (used to be XML but could use JSON, other?) hotels in hawthorne pizza in atlanta Wellesley Inn 540 Saw Mill River Rd. Elmsford, NY 10523

© 2010 Noah Mendelsohn AJAX Application – Google Maps …Data used to drive formatting of points of interest hotels in hawthorne pizza in atlanta Wellesley Inn 540 Saw Mill River Rd. Elmsford, NY 10523

© 2010 Noah Mendelsohn AJAX Application – Google Maps …and XSLT in the browser converts that to HTML hotels in hawthorne pizza in atlanta Wellesley Inn 540 Saw Mill River Rd. Elmsford, NY 10523

© 2010 Noah Mendelsohn AJAX Application – Google Maps

© 2010 Noah Mendelsohn Question: What would happen if we built the Web from RPC? --- Revisited!

© 2010 Noah Mendelsohn Why not use RPC for the Web?  No uniform interface –You’d need an interface definition to follow a link  No global naming  Most RPC data types poorly tuned for documents

© 2010 Noah Mendelsohn Why not use RPC for the Web?  No uniform interface –You’d need an interface definition to follow a link  No global naming  Most RPC data types poorly tuned for documents  No safe methods

© 2010 Noah Mendelsohn Why not use RPC for the Web?  No uniform interface –You’d need an interface definition to follow a link  No global naming  Most RPC data types poorly tuned for documents  No safe methods  No content negotiation

© 2010 Noah Mendelsohn HTTP Content Negotiation

© 2010 Noah Mendelsohn Content negotiation for language HTTP GET Host: webarch.noahdemo.com GET /demo1/test.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is Accept-language: en-us I prefer English, please! But: it is OK to also provide individual URIs for each language version

© 2010 Noah Mendelsohn Content negotiation for device HTTP GET Host: webarch.noahdemo.com URI is GET /demo1/test.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us User-Agent: Mozilla/4.0 Firefox

© 2010 Noah Mendelsohn Content negotiation for device Host: webarch.noahdemo.com GET /demo1/test.html HTTP/1.0 Host: webarch.noahdemo.com User-Agent: Noahs Demo HttpClient v1.0 Accept: */* Accept-language: en-us URI is User-Agent: Cell Phone Browser V1.1 Cell phone browser HTTP GET

© 2010 Noah Mendelsohn Device independence The same URI works across devices… …you can see my reservation from your cell phone Even phone numbers are on the Web

© 2010 Noah Mendelsohn Summary

© 2010 Noah Mendelsohn Summary  HTTP and the REST model are designed to meet the unique needs of the Web  Document-oriented  Discoverable  Stateless  Extensible  Global scale  Supports unique features like content negotiation