Skip to content

Instantly share code, notes, and snippets.

@garciadanny
Last active October 12, 2016 09:21
Show Gist options
  • Save garciadanny/6896044 to your computer and use it in GitHub Desktop.
Save garciadanny/6896044 to your computer and use it in GitHub Desktop.
A beginners guide to HTTP and REST. Notes taken from codecademy.com

#HTTP and REST

Hypertext Transfer Protocal

  • Whenever you navigate a site though links, you're making a state transition, bringing you to the next page. Representing the next state of the application.
Client sends request to server, server returns a response.
  • In order for a client and a server to speak to each other, they follow a set of principles called REST (Representational State Transer).

API

  • An API specifiys the ways a program can interact with an application, it specifies the process for authentication, important URLs, classes, methods, etc.
A RESTful API is:
  1. Seperate from client and server.

  2. Doesn't hold state between requests.

  • Meaning that all the info necessary to respond to a request is available in each request. No data (state) is ever held by the server from request to request.
  1. Uses HTTP and HTTP methods ( GET POST PUT DELETE ).

HTTP Request

Is made up of 3 parts:
  1. The request line:

    • Tells the server what type of request is being sent (http verbs).
    • and tells ther server what resource it's looking for.
  2. The header:

    • Sends the server additional info such as which client is sending the request.
  3. The body:

    • This is empty in a GET request, but this is where the info would go if you were sending a PUT or POST request to the server.

HTTP Response

Is made up of 3 parts:
  1. The response line:
    • Includes HTTP status code.
  2. Header:
    • Includes further info about the server and it's response.
  3. Body:
    • Contains the text of the response.

Endpoints

Are API-DEFINED locations where particular data is stored.
Ex:

If you're using the api from a video hosting service, there may be different endpoint for "Most popular videos", "Most viewed videos", etc…

You'll GET something different depending on which endpoint you send a GET request to.

Authentication & API Keys

API keys identify you to the API. They help API providers keep track of how their service is used and to prevent unauthroized and malicious activity.

OAuth
Is a protocol used by APIs to authenticate a client.

HTTP Status Codes

Every response from the server will contain a 3-digit status code.

  1. 1xx - The server says it's working on your request.
  2. 2xx - When the server is successfully responding to your request.
  3. 3xx - The server says "I can do what you want but I have to do something else first". Ex: The server may have to reroute the request to get the resource you're asking for.
  4. 4xx - You probably made a mistake. Ex: 404 "file not found". When you ask for a resource or web page that does not exist.
  5. 5xx - The server can't successfully respond to your request.

XML

E x tensible Markup Language

  • Similar to HTML where you have tags between angle brackets, except you get to define those tags. Whereas HTML has pre-defined tags decided on by the W3C.
<pet>
 <name>Jeffrey</name>
 <species>Giraffe</species>
</pet>

JSON

Java S cript Object Notation

{
  "pets": {
    "name": "Jeffrey",
    "species": "Giraffe"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment