Reading 6 HTTP and REST - liz-kavalski-401-advanced-javascript/seattle-javascript-401n13 GitHub Wiki

HTTP: The Protocol Every Web Developer Must Know - Part 1

  • HTTP stands for Hypertext Transfer Protocol
  • 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.
  • Uniform Resource Locators (URLs) = web communications is the request message
  • The protocol is typically http
    • can also be https for secure communications.
  • GET: fetch an existing 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.
  • The status code is important and tells the client how to interpret the server response.
    • 100 messages = telling the client to continue sending the remainder of the request, or ignore if it has already sent it.
    • 200 message = OK
    • 300 message = redirected/moved
    • 400 message = client error
    • 500 message = server error
  • Headers to provide meta-information about the the content
    • Content- prefixed headers provide information about the structure, encoding and size of the message body.
    • The 'Expires' header indicates a timestamp of when he entity expires.
  • Has an example of what a request format look like (about 1/2 through the page) https://code.tutsplus.com/tutorials/http-the-protocol-every-web-developer-must-know-part-1--net-31177
  • 'Accept' prefixed headers indicate the acceptable media-types, languages and character sets on the client
  • 'From, Host, Referer and User-Agent' identify details about the client that initiated the request.
  • The 'If-' prefixed headers are used to make a request more conditional, and the server returns the resource only if the condition matches.
  • There are tools for inspecting/veiwing HTTP traffic

Why Swagger API documentation

  • A to document API
  • which help people understand how to use the API