Hypertext Transfer Protocol (HTTP) is a protocol that provides a standardized way for computers to communicate with each other. It has been the foundation for data communication over the internet since 1990 and is integral to understanding how client-server communication functions.
Features
- Connectionless: When a request is sent, the client opens the connection; once a response is received, the client closes the connection. The client and server only maintain a connection during the response and request. Future responses are made on a new connection. In other words, Client opens one connection for each request, which is closed once the server responds.
- Stateless: There is no dependency between successive requests. In other words, no information is required from one request in order to process a subsequent request.
- Not Sessionless: Utilizing headers and cookies, sessions can be created to allow each HTTP request to share the same context. HTTP requests can share the same context using tools such as cookies.
- Media Independent: Any type of data can be sent over HTTP as long as both the client and server know how to handle the data format. For example, JSON format. HTTP requests can include any type of data as long as both the server and client know how to handle that data type.
HTTP Elements
- Uniform Resource Identifier (URIs)
- Messages: Requests and Responses
- Status Codes (e.g. 404 NOT FOUND)
Elements
- Universal Resource Identifiers (URIs): An example URI is http://www.example.com/tasks/term=homework. It has certain components:
- Scheme: specifies the protocol used to access the resource. HTTP or HTTPS. In the above example, http
- Host: specifies the host that holds the resources. In the above example, www.example.com
- Path: specifies the specific resource being requested. In the above example, /tasks
- Query: an optional component, the query string provides information the resource can use for some purpose such as a search parameter. In the above example, /term=homework
URI vs URL
You may be unsure what the difference is between a URI (Universal Resource Identifier) and a URL (Universal Resource Locator).
The term URI can refer to any identifier for a resource - for example, it could be either the name of a resource or the address (since both the name and address are identifiers of that resource).
In contrast, URL only refers to the location of a resource. In other words, it only ever refers to an address.
Thus, URI could refer to a name or an address, while URL only refers to an address. URLs are a specific type of URL that is used to locate a resource on the internet when a client makes a request to a server.
What is the difference between URI and URL?