Repository navigation
Reading 07
HTTP and REST
HTTP stands for Hypertext Transfer Protocol. It's a stateless, application-layer protocol for communicating between distributed systems, and is the foundation of the modern web. Communication between a host and a client occurs, via a request/response pair. The client initiates an HTTP request message, which is serviced through a HTTP response message in return. We will look at this fundamental message-pair in the next section.
URLs At the heart of web communications is the request message, which are sent via Uniform Resource Locators (URLs). URLs reveal the identity of the particular host with which we want to communicate, but the action that should be performed on the host is specified via HTTP verbs.
Request Verbs GET: fetch an existing resource. The URL contains all the necessary information the server needs to locate and return the resource. POST: create a new resource. POST requests usually carry a payload that specifies the data for the new resource. PUT: update an existing resource. The payload may contain the updated data for the resource. DELETE: delete an existing resource. HEAD: this is similar to GET, but without the message body. It's used to retrieve the server headers for a particular resource, generally to check if the resource has changed, via timestamps. TRACE: used to retrieve the hops that a request takes to round trip from the server. Each intermediate proxy or gateway would inject its IP or DNS name into the Via header field. This can be used for diagnostic purposes. OPTIONS: used to retrieve the server capabilities. On the client-side, it can be used to modify the request based on what the server can support. Status Codes With URLs and verbs, the client can initiate requests to the server. In return, the server responds with status codes and message payloads.