Hello! Welcome to your next lesson.
In our last session, you successfully built a complete user authentication system for a web application. You learned how a user interacts with a server through a web browser, submitting forms and navigating pages. This is a classic user-to-application communication model.
Today, we're shifting our focus to a different, but equally important, communication model: application-to-application. This is where Application Programming Interfaces (APIs) come in. The learning outcome for this lesson is to explain RESTful API principles: resources, HTTP verbs, and status codes.
Understanding these principles is essential for your goal of becoming a Full Stack AI Developer. Your AI models won't live in isolation; they will need to be exposed through APIs so that web front-ends, mobile apps, or other backend services can use their predictions.
Let's dive into the architectural style that powers most of the modern web: REST.
1. What is an API and What Makes it "RESTful"?
An Application Programming Interface (API) is a set of rules and definitions that allows two software applications to communicate with each other. Think of it as a contract: one application offers a set of services, and the API defines how other applications can request those services.
REST, which stands for REpresentational State Transfer, is not a protocol or a specific technology. Instead, it's an architectural style—a set of guiding principles for designing networked applications. APIs that follow these principles are called RESTful APIs.
To get a quick and clear overview, let's start with a short video.
What Is REST API? Examples And How To Use It: Crash Course System Design #3
This video from ByteByteGo provides a concise introduction to what a REST API is and why it's so widely used.
Watch the first two sections of the video (00:07 to 01:27). Pay attention to the definition of an API and the core idea of organizing information into 'resources'.
The key takeaway is that REST provides a standardized way for computers to communicate over the internet. This standardization makes APIs predictable and easy for developers to work with.
This diagram illustrates the basic architecture. A client (like a mobile app or a web browser) sends a request to an API, which then interacts with resources on a server and sends a response back.

For a deeper understanding of the core principles that define the REST architectural style, please read the following sections from the article "HTTP, REST Principles, and API Design Fundamentals."
HTTP, REST Principles, and API Design Fundamentals
This article provides a thorough explanation of HTTP and the foundational principles of REST. We'll focus on the 'why' behind REST first.
Read the section titled 'REST Principles and API Design Fundamentals,' focusing on the 'Core Principles of REST' (Client-Server, Statelessness, Cacheability, Layered System, and Uniform Interface). You can stop before the subsection 'Designing RESTful APIs: Fundamentals.'
Let's quickly summarize two of the most important principles you just read about:
- Client-Server Separation: The client (which handles the user interface) and the server (which handles data storage and logic) are completely separate. They evolve independently, communicating only through the API. This is why you can use the same Instagram API for both their iPhone app and their Android app.
- Statelessness: Each request from the client to the server must contain all the information the server needs to understand and process it. The server does not store any information about the client's session. This makes the system highly scalable, as any server can handle any request.
2. The Three Pillars of a RESTful Interface
The "Uniform Interface" principle you read about is what makes REST APIs so consistent and intuitive. It's built on three pillars: Resources, HTTP Verbs, and Status Codes.
Pillar 1: Resources (The Nouns)
In REST, every piece of information is treated as a resource. A resource is an object or entity that can be uniquely identified. Examples include: a user, a product, an article, or even a collection of users.
Resources are identified by a Uniform Resource Identifier (URI), which is the endpoint or URL. The key convention in REST is to use nouns to name your resources, not verbs.
- Good (Nouns):
/users(A collection of all users)/users/123(A specific user with ID 123)/products(A collection of all products)
- Bad (Verbs):
/getAllUsers/createNewUser/deleteProduct?id=456
The action to be performed is not part of the URL. So how do we tell the server what to do? That's where the second pillar comes in.
Pillar 2: HTTP Verbs (The Actions)
The action you want to perform on a resource is defined by the HTTP method (or verb) you use in your request. This neatly maps to the CRUD (Create, Read, Update, Delete) operations you've encountered when working with databases.
HTTP, REST Principles, and API Design Fundamentals
Let's dive into the specifics of what each HTTP method does. This section of the same article provides a detailed breakdown.
Read the subsection 'HTTP Methods (Verbs)'. Pay close attention to the meaning of GET, POST, PUT, DELETE, and PATCH. Note the concept of 'idempotency'—it's an important one.
Here is a summary of the primary verbs:
| HTTP Verb | CRUD Operation | Description | Idempotent? |
|---|---|---|---|
| GET | Read | Retrieves a representation of a resource. | Yes |
| POST | Create | Creates a new resource. | No |
| PUT | Update | Replaces an entire resource with new data. | Yes |
| PATCH | Update | Applies partial modifications to a resource. | No |
| DELETE | Delete | Deletes a specified resource. | Yes |
Idempotency is a key concept: an operation is idempotent if making the same request multiple times has the same effect as making it once.
DELETE /users/123is idempotent. The first call deletes the user. Subsequent calls will do nothing new (the user is already gone).POST /usersis not idempotent. Each call will create a new, separate user.
Pillar 3: Status Codes (The Response)
After the server processes the client's request, it sends back a response. A critical part of this response is the HTTP status code, a three-digit number that tells the client the outcome of the request.
You've already seen some of these, like 200 OK for a successful page load or 404 Not Found for a broken link. In the context of an API, they provide a structured way to handle success and failure.
HTTP, REST Principles, and API Design Fundamentals
Finally, let's look at how the server communicates the result of a request. This section details the different classes of status codes.
Read the section 'HTTP Status Codes'. Focus on understanding the five main classes (1xx, 2xx, 3xx, 4xx, 5xx) and the specific meaning of the most common codes listed.
Here are the most common status codes you'll work with:
- 2xx (Success)
200 OK: Standard success response forGET,PUT,PATCH.201 Created: The request succeeded and a new resource was created (used withPOST).204 No Content: The request succeeded, but there's no data to return (used withDELETE).
- 4xx (Client Error)
400 Bad Request: The server couldn't understand the request (e.g., invalid JSON).401 Unauthorized: Authentication is required and has failed.403 Forbidden: The client is authenticated but doesn't have permission to access the resource.404 Not Found: The requested resource could not be found.
- 5xx (Server Error)
500 Internal Server Error: A generic error indicating something went wrong on the server.
3. Putting It All Together
Let's see how these three pillars work in harmony. This table shows a typical set of RESTful API endpoints for managing user resources.
Notice the pattern:
- The Path (
/api/v1/users) is always a noun. - The HTTP Method (
GET,POST,PUT,DELETE) specifies the action. - The Status Code (
200,201,204) confirms the result.
This predictable structure is the power of REST. Once you understand the pattern for one resource, you can easily predict how to interact with any other resource in the API.
Conclusion
In this lesson, you've learned the fundamental principles of RESTful API design. This architectural style is not just a technical detail; it's a philosophy for building scalable, maintainable, and predictable web services.
Key Takeaways:
- REST is an architectural style for designing APIs based on a set of constraints.
- Resources are the "nouns" of your API, identified by unique URIs (e.g.,
/tasks,/tasks/1). - HTTP Verbs are the "actions" you perform on resources (
GET,POST,PUT,PATCH,DELETE). - Status Codes are used by the server to communicate the outcome of a request back to the client (
2xxfor success,4xxfor client errors,5xxfor server errors). - Together, these principles create a uniform interface that makes APIs consistent and easy to use.
In our next lesson, we will move from theory to practice. You'll learn how to build a RESTful API supporting CRUD operations using Flask-RESTful, applying the principles you learned today to create your first set of API endpoints.