#HTTP and REST
- 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.
- In order for a client and a server to speak to each other, they follow a set of principles called REST (Representational State Transer).
- An API specifiys the ways a program can interact with an application, it specifies the process for authentication, important URLs, classes, methods, etc.
-
Seperate from client and server.
-
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.
- Uses HTTP and HTTP methods ( GET POST PUT DELETE ).
-
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.
-
The header:
- Sends the server additional info such as which client is sending the request.
-
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.
- The response line:
- Includes HTTP status code.
- Header:
- Includes further info about the server and it's response.
- Body:
- Contains the text of the response.
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.
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.
Every response from the server will contain a 3-digit status code.
- 1xx - The server says it's working on your request.
- 2xx - When the server is successfully responding to your request.
- 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.
- 4xx - You probably made a mistake. Ex: 404 "file not found". When you ask for a resource or web page that does not exist.
- 5xx - The server can't successfully respond to your request.
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>
Java S cript Object Notation
{
"pets": {
"name": "Jeffrey",
"species": "Giraffe"
}
}