REST Flashcards
What is API?
- API = Application Programming Interface
- Application = any software with a distinct function
- Interface = contract between the application through which the
function can be accessed from the surrounding world - Programming = the application interface can be accessed programmatically, i.e., from another software
- Compare to UI (Application User Interface)
API (Application Programming Interface) is a set of rules and protocols that allows interaction between different software components or services.
What is REST?
REST = Representational State Transfer
Software architectural style for building distributed hypermedia
Set of following architectural principles (REST)
- resource orientation
- unique resource identification
- stateless client/server interaction
- uniform interface
Resource Orientation
- resource = concrete or abstract thing/action we want to publish
—* everything is a resource in REST - resource representation ~ state of the resource
—* document that can be sent between communicating peers
—* representation format needs to be established
—-different (meta-)formats may be used(HTML, XML, JSON, RDF, AtomPub, …)
—each resource can have more representations ,in different formats
— dataformats==mediatypes - representation contains links to related resources
—* representation format must support links
—* applications that consume resources navigate instead of calling
—* navigation = transition to next state
Unique Resource Identification
- each resource has a unique ID (name)
- need to distinguish resource ID from resource representation ID
Stateless Client/Server Communication
Each request from the client contains all the necessary data to process the request on the server. The server does not persist state between requests from the same client, making it easier to scale and improve system reliability.
Resource Manipulation
- uniform interface for resource manipulation
- do not encode verbs into resource identifiers
Uniform Interface: The RESTful API provides a uniform interface for interacting with resources. This includes using standard HTTP methods (GET, POST, PUT, DELETE, and others) to perform operations on resources, as well as uniform conventions for identifying resources via URI (Uniform Resource Identifier), data formatting (e.g., JSON, XML), and others. aspects of interaction with resources.
HTTP-methods and REST
The RESTful API relies on a limited set of HTTP methods such as GET, POST, PUT, and DELETE to perform operations on resources on the server, while the API may use different methods depending on the implementation.
REST FORMATS
An API can have various data transfer formats such as XML, JSON, SOAP, etc. while a RESTful API usually uses the JSON format for data transfer.
REST Identification
The RESTful API uses a URI (Uniform Resource Identifier) to identify resources on the server, while an API can use a variety of methods and ways to identify resources.
Stateless
The RESTful API is built on the principle of “Stateless” (stateless), which means that each request from the client contains all the necessary data to process the request on the server. The API, in turn, can be either “Stateless” or “Stateful” (stateful), depending on the implementation.
REST HTTP status codes
RESTful APIs typically use HTTP status codes to indicate the result of an operation, such as 200 OK, 201 Created, 404 Not Found, etc. The API can also use HTTP status codes, but this is not a requirement.
Caching
Caching: The RESTful API supports caching, which allows clients to keep local copies of resources on their side to improve performance and reduce server load.
Client-server architecture
Client-server architecture: The system is divided into a client part, which is responsible for the user interface and user interaction, and a server part, which processes requests from clients and manages resources. This allows you to independently develop the client and server parts of the system.
REST != HTTP
HTTP (Hypertext Transfer Protocol) is one of the most common protocols used to implement RESTful APIs. However, REST and HTTP are different things. REST defines the architectural principles for organizing communication between a client and a server, while HTTP is a data transfer protocol used to exchange information between a client and a server.