HTTP Summary, Review

CSCI-UA.0480-008

HTTP?

What's HTTP?

  • it's the protocol used by the world wide web (you know, a bunch of interconnected documents, identified by URLs)
  • it's a request-response protocol between a client and a server
  • the client sends request, and the server sends back a response

HTTP Request

What does an actual HTTP request look like?

  • a request line … a request method and a path - GET /teaching HTTP/1.1
  • request headers (one per line) Host: jvers.com, User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101
  • an empty line
  • an optional body

GET /~jversoza/ HTTP/1.1
Host:cs.nyu.edu

HTTP Request Methods

HTTP supports a few different request methods - these methods (sometimes called verbs) specify the kind of action to be performed on the document/resource requested. What are some HTTP request methods?

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD

HTTP Request Methods Continued

So, if request methods specify some action on a requested resource, what's the difference between GET and POST?

  • GET retrieves a resource (reads a resource)
  • POST asks the server to store or update data (usually related to the resource itself) using the data supplied in the request body

HTTP Response

What does the response to a request look like?

  • a status-line … which includes a status code and reason - HTTP/1.1 200 OK
  • response header fields - Content-Type: text/html
  • an empty line
  • an optional message body - usually an HTML document!

HTTP/1.1 200 OK
Date: Tue, 29 Sep 2015 11:53:39 GMT
Server: Apache/2.2.15 (Red Hat)
...
(html document) ...

HTTP

What are some HTTP response codes?

  • 200 - OK
  • 404 - Not Found
  • 500 - Server Error

HTTP

What are the classes of response coes?

  • 1xx - informational
  • 2xx - success
  • 3xx - redirect
  • 4xx - client error
  • 5xx - server error

URLs

What are the parts of a URL?

  • scheme/protocol - http
  • domain or actual ip address - pizzaforyou.com
  • port (optional) - 80 (default if http)
  • path - /search
  • query_string (optional) - ?type=vegan
  • fragment_id (optional) - #topresult


scheme://domain:port/path?query_string#fragment_id

http://pizzaforyou.com:80/search?type=vegan#top_result

Clients

What are some tools that we use to make HTTP requests… and how do we use them?

  • nc hostname port
  • curl hostname
  • Chrome!


Let's see them in action.