HTTP and REST - 401-advanced-javascript-billybunn/seattle-javascript-401d29 GitHub Wiki
HTTP and REST
Largely based on a reading of HTTP: The Protocol Every Web Developer Must Know by Pavan Podila and a viewing of What Is A RESTful API? Explanation of REST & HTTP by Traversy Media.
Summary
What is a REST API?
What is an API?
Application Program Interface
This is a broad, generalized term referring to a contract provided by one piece of software sent to another piece of software. "Give me this information formatted in this way, and I'll give you this data formatted in this way."
API Analogy
In a restaurant, there is a customer at a table, a kitchen, and a waiter. In this scenario, the waiter is the API. He is formatted to take a certain order in a certain way, and then bring back a certain meal. So an API is basically a messenger or a waiter between running software.
What is REST?
Representational State Transfer
- Architecture style for designing networked applications
- Relies on a stateless, client-server protocol, almost always HTTP
- Treats server objects as resources that can be created or destroyed
- Can be used by virtually any programming language
An API is a messenger, and REST lets us use HTTP requests to format those messages. "RESTful API" refers to an API that conforms to the REST constraints.
HTTP Methods
GET
Retrieve data from a specified resource
POST
Submit data to be processed to a specified source
PUT
Update a specified resource
DELETE
Delete a specified resource
Less-common HTTP methods:
HEAD
Same as get but does not return a body
OPTIONS
Returns the supported HTTP methods
PATCH
Update partial resources
Authentication
Some API's require authentication to use their service. This could be free or paid.