HTTP and REST - 401-advanced-javascript-davetrost/alchemy-fsjs-fall-2019 GitHub Wiki

Reading Materials

REST details

  • REST stands for REpresentational State Transfer
  • REST typically is implemented using HTTP and JSON
  • The REST definition includes 6 constraints on clients and servers:
    • Uniform Interface: this constraint simplifies and decouples the architecture, enabling each part to evolve independently. For us this means: HTTP Verbs (GET,POST,PUT,DELETE), URIs (resource name), HTTP response (status and body)
    • Stateless: every request to the server must contain all of the information necessary to get the desired result
    • Cacheable: because many clients can access the same server, the server has the authority/ability to cache responses for faster response time
    • Client-Server: the interface between client and server enables separation of concerns. Client: concerns of interface, portability, user state, etc. Server: concerned with data storage. The static interface allows freedom of development and replacement of servers and/or clients.
    • Layered System: server-side responses may come from a single machine or from a set of intermediary servers in adidiont to the primary server. These configuration options are available on the server-side without having undo impacts on the client.
    • Code-On-Demand (optional): it is not prohibited to have the client run some of the server logic when this approach may be faster or more efficient.

HTTP Details

  • Communication between a host and a client occurs via a request/response pair. The client initiates the request. The server gives an HTTP response.
  • HTTP is a versioned protocol. Current version is 1.1
  • Breakdown of a URL
    • https://www.domain.com:1234/path/to/a/resource?a=b&x=y
    • https - protocol
    • www.domain.com - host
    • 1234 - port
    • path/to/a/resource - resource path
    • a=b&x=y - query
  • HTTP Verbs (the big 4):
    • GET
    • POST
    • PUT
    • DELETE
  • HTTP Status Codes:
    • 100 to 199 - Indicates an informational message
    • 200 to 299 - Indicates a successful message
    • 300 to 399 - Indicates a redirection message
    • 400 to 499 - Indicates a Client Error
    • 500 to 599 - Indicates a Server Error
  • Web Frameworks and Libraries that can be used to create HTTP servers:
    • ExpressJS (a library for Node.js) which is based on and shares similar language with a Ruby Web framework called Sinatra
    • Ruby on Rails
    • jQuery Ajax - this is an interesting library because it is client-side-centric. As such, it is an inversion of other frameworks used to create HTTP servers. Ajax allows us to read responses and modify requests.