REST API Flashcards
What is a REST API?
REST API is an API that follows the guideline provided by REST.
The Three key elements of REST Api paradigm are:
- Client software on user computer used to initiate communication with server
- Server offers an API as a means of access to its data or features.
- Resource is any piece of content that the server can provide to the client
For the client to gain access to a resource from the server, the client must make an HTTP request to the API endpoint
The server then sends the client an HTTP response with encoded data on the resource
What is an API?
an API is the tech that glues together all the pieces of the digital universe by serving as a communication middleman for each piece.
An API is an Application Programming Interface which basically acts as a middleman for applications to communicate with each other
this allows programmers to program systems to communicate with other systems, without either system knowing the inner workings of the system
a web api facilitates the exchange of formatted queeriees between clients and serveres
What are the three principles that serve as the pillars of API?
- Limited Access: client only has access to the specific resource its requesting as defined by the route
- System independent: regardless of changes to the inner system, the API still works i.e. a jukebox can have different mechanics but the api of delivering/playing music is the same and is functional either way
- Simple in use: should be easy to use and difficult to misuse. Should be easy to do simple tasks, possible to do complex tasks, and impossible/difficult to do wrong tasks.
Reuse depends on
- good design
2. great documentation
What is the structure of a REST Request?
a REST request includes an HTTP method, an API endpoint, headers, and
a body
What is an HTTP method?
an HTTP method describes that action to be done to the resource. There are 4 methods known as CRUD:
POST to Create a resource
GET to Retrieve a resource
PUT to Update a resource
Delete to Delete a resource
What is an endpoint?
an endpoint contains a Uniform Resource Identifier (URI) indicating where and how to find the resource on the internet.
the most common type of Uniform Resource Identifier is the Uniform Resource Location (URL) which serves as a complete web addres
What are Headers?
Headers store information relevant to both the client and the server
Mainly, headers provide authentication data - an API key, name or IP address of the computer where the server is installed, and the info about the response format
Headers have 3 pieces of info:
- authentication info
- location/destination of the server
- info about the response format
What is the body?
the body is used to convey additional info to the server. For instance, it could be a piece of data you want to add or replace
What is the response?
the server doesn’t send the resource itself, instead it sends its representation - a machine-readable description of its current state
it can be represented in many formats but mainly XML or JSON
What makes an API RESTful?
The idea of REST is to organize interactions between two independent machines, the client and the server
REST is a set of constraints to guide and describe how the server processes requests and responds to them
The constraints outlined by REST adds properties to the system that makes it more desirable
What are the constraints outlined in REST?
Client-Server Autonomy
Uniform Interface
Layered Architecture
Caching
Stateless Interactions
Code on Demand
Priority of Business Needs
REST Constraint 1) Client-Server Autonomy.
What is the Client-Server Autonomy constraint?
Client-Server Autonomy mean that client and server work independently using to two separate tech stacks.
There is a separation of responsibilities between the client and the server
The client does not need to know about how inner working of the server (i.e. business logic) and the server doesn’t need to know the inner workings of the client (i.e. user interface)
What are the desirable properties gained from Client-Server Autonomy?
since the client doesn’t depend on the inner workings of the server and the server doesn’t depend on the inner workings of the client, the client (API consumer) and the server (API provider) can be modified without disrupting the communication or service between the two.
Properties: modifiability, improved system reliability
What is meant by the REST constraint of Uniform Interface?
Uniform Interface dictates a standardized way to communicate with a given server. The server uses the same interface for all clients and requests.
The standardization requires:
- Unique resource identifier assigned to each resource
- Self-descriptive messages explaining how to interpret them and what to do next
- The ability to manipulate a resource through its representation in JSON or XML
- Hypermedia linking to related resources
Uniform interface should help developers easily grasp the logic of an API.
Properties gained: Ease of use, shared understanding