Course Content
Professional Web API with Flask
Professional Web API with Flask
About REST API
In the previous chapter, we discussed Web APIs and their role in linking various applications across the internet. Moving forward, we'll explore a distinct category of Web API known as REST API. REST, short for Representational State Transfer, functions as a protocol that APIs utilize for communication. Picture yourself at MacDrive, selecting a menu item. You make a specific request and receive exactly what you ordered. Similarly, REST APIs facilitate a standardized and effective way for different computer systems to communicate over the internet.
REST APIs adhere to several key principles:
- Uniform Interface: this principle standardizes the interaction between client and server, enhancing compatibility across different systems;
- Client-Server Architecture: in this model, the client (such as your web browser) and the server (where data is stored) function independently. Clients are only required to know resource URIs;
- Statelessness: every request from a client must contain all the information necessary for the server to fulfill that request. The server does not retain memory of past requests, treating each one as new;
- Cacheability: similar to how you might store snacks in your backpack for later, responses can be cached for faster retrieval;
- Layered System: REST supports a tiered system architecture, allowing APIs to be hosted on one server, data to be stored on another, and requests to be authenticated on yet another. Typically, a client cannot distinguish if it is connected directly to the end server or an intermediary;
- Code on Demand: this optional feature allows servers to send executable code to clients as part of the response, like JavaScript, enabling clients to temporarily enhance their functionality. This is akin to a web page that provides not only data (HTML, CSS) but also interactive features (JavaScript).
The uniform interface of REST is defined by specific HTTP request types, each serving a unique function:
- GET: utilized for retrieving information. For example, when you access a webpage, your browser issues a GET request to fetch the content. Similarly, you can request a single item or multiple items from a list, like ordering a burger, cola, or chips separately;
- POST: used to create a new resource, like posting a new blog entry on a server;
- PUT: updates existing resources;
- DELETE: removes resources.
These HTTP requests encompass CRUD (Create, Read, Update, Delete) functionalities, enabling developers to build efficient, robust applications that communicate effectively within the vast digital landscape.
Thanks for your feedback!