HTTP

HyperText Transfer Protocol

What is HyperText?

besides a really old and outdated term

HyperText refers to on screen text that can contain references (hyperlinks) to other HyperText.

 

The content that the term HyperText refers to can be plain text, structured data, hyperlinks, tabular data, images and other media that can be presented on the screen.

Don't say HyperText!

We don't use the term HyperText anymore.

It just exists in our acronyms: HTTP and HTML

just use the more descriptive form: HTML content, XML data, Json document, etc.

What is HTTP?

a protocol used to transfer Hypertext

HTTP is a "language" spoken between clients and servers

Internet Data

An HTTP client makes HTTP requests

An HTTP server accepts HTTP requests, and sends the client an HTTP response

HTTP connections

the default designated port for HTTP servers to listen on is the reserved port 80

HTTP connections are created and data is transmitted through sockets

Once the server responds, the socket is closed

HTTP Request Methods

A client uses one of the methods to send HTTP Requests to the server

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD
  • OPTIONS
  • I want a resource
  • I want to send you data
  • I want to change a resource
  • I want to delete a resource
  • I just want the response headers
  • What methods can I use?

HTTP Request URI

Uniform Resource Identifier

A URI is how a server identifies a resource to be delivered to the client

/index.html

/map/21.3088569,-157.8084575

Examples:

URL

A URL is a URI that also specifies how to get that resource (what protocol to use)

Uniform Resource Locator

https://www.google.com

http://www.devleague.com/apply

Examples:

https://www.google.com

http://www.devleague.com:80/apply

http://162.243.46.54:80/parting-thoughts-from-a-student/

Protocol

Host address

path

port

HTTP Request

the default port to make HTTP requests is 80

The HTTP Request Response cycle starts with the HTTP Request

An HTTP Request is a client connecting to a host (server that is listening for incoming messages) and sending a Request Message 

HTTP Request

The HTTP Request Message contains a Header and Body

separated by a blank line

HTTP Request

The HTTP Request Message Header contains

Request Line which is the first line of the header,

and Request Headers which is a variable number of key value pairs

HTTP Request

[METHOD] [Request URI] [HTTP Version]

Header Request Line

The request line adheres to this format

Examples

GET /index.html HTTP/1.1
GET / HTTP/1.1
POST /login HTTP/1.1

HTTP Request

Headers

Key value pairs separated by ":"

multiple values can be separated by ","

Host: www.devleague.com
Connection: Keep-Alive
Accept: text/html, application/json
Date: Wed, 8 Jul 2015 11:12:31 GMT

HTTP Request

Body

A request body may be sent to the server.

The body content begins after an empty line after the headers.

Use the content-length header to tell the server how large the message body is.

POST /apply HTTP/1.1
Host: www.devleague.com
Connection: Keep-Alive
Accept: text/html, application/json
Content-Length: 278
firstName=test&lastName=test&email=test%40test.com&phone=8082233899&address1=test&address2=&city=test&state=test&postal=test&country=US&track=55103a9f50b6d0603be3f71b&status=total+noob&employment=student&whyAttend=test&aboutSelf=test&reference=test&referral=&applyScholarship=no

HTTP Response

An HTTP Response is the server replying to the client's original HTTP Request with a message and the requested resource

HTTP Response

Message

The HTTP Response Message is formatted in a similar way to the HTTP Request Message

HTTP Response

Status Line

[HTTP Version] [HTTP Status Code] [Reason Phrase]

The status line adheres to this format

Examples

HTTP/1.1 200 OK
HTTP/1.0 404 Not Found
HTTP/1.1 403 Forbidden
HTTP/1.1 500 Internal Server Error
HTTP/1.1 302 Found
HTTP/1.1 304 Not Modified

HTTP Response

Headers

Key value pairs separated by ":"

multiple values can be separated by ","

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 08 Jul 2015 22:31:15 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 40489
Connection: keep-alive

HTTP Response

Body

The body content contains the resource that was requested.

The headers usually contain metadata describing how to handle the body content.

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 08 Jul 2015 22:31:15 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 40489
Connection: keep-alive

<html class="no-js" lang="en">
  <head>...

Tools

Resources

HTTP

By Jon Borgonia

HTTP

Basics

  • 3,709