Reading Class 06 - meron-401n14/seattle-javascript-401n14 GitHub Wiki

HTTP

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.

HTTP

BasicsHTTP allows for communication between a variety of hosts and clients, and supports a mixture of network configurations.

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.

URLs

At the heart of web communications is the request message, which are sent via Uniform Resource Locators (URLs). 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. 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. The status code is important and tells the client how to interpret the server response. The HTTP spec defines certain number ranges for specific types of responses: **1xx: **Informational Messages This class of codes was introduced in HTTP/1.1 and is purely provisional. The server can send a Expect: 100-continue message, telling the client to continue sending the remainder of the request, or ignore if it has already sent it. HTTP/1.0 clients are supposed to ignore this header. 2xx: Successful This tells the client that the request was successfully processed. The most common code is 200 OK. For a GET request, the server sends the resource in the message body. 3xx: Redirection This requires the client to take additional action. The most common use-case is to jump to a different URL in order to fetch the resource. 4xx: Client Error These codes are used when the server thinks that the client is at fault, either by requesting an invalid resource or making a bad request. The most popular code in this class is 404 Not Found, which everyone will identify with. 404 indicates that the resource is invalid and does not exist on the server. 5xx: Server Error This class of codes are used to indicate a server failure while processing the request. The most commonly used error code is 500 Internal Server Error.