Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 12

Introduction to RESTful API Design Principles

Recommended resources

Welcome back! In our last lesson, we explored the fundamentals of HTTP, learning about the request-response cycle, methods, and status codes. Think of those as the essential vocabulary of the web. Today, we'll build on that foundation to learn the grammar: the rules and conventions that turn those individual words into coherent, scalable, and maintainable conversations.

This lesson directly addresses the learning outcome: Describe the basic principles of RESTful API design. REST (Representational State Transfer) is the architectural style that underpins the vast majority of modern web APIs. Mastering these principles is a non-negotiable step toward your goal of designing and developing REST APIs as a backend engineer at a company like Infilect.

By the end of this session, you'll understand the core constraints that define a RESTful API and be able to distinguish a truly RESTful endpoint from a simple JSON-over-HTTP service.

1. What is REST? A High-Level Overview

Before diving into the detailed rules, let's get a quick, big-picture understanding of what REST is and why it's so dominant in web development. REST isn't a strict protocol or standard; it's an architectural style, a set of guiding principles for designing networked applications.

The short video from ByteByteGo provides an excellent and concise introduction to the concept.

What Is REST API? Examples And How To Use It: Crash Course System Design #3

This video quickly defines REST and introduces its fundamental concepts, like resource-based URIs and the use of HTTP verbs.

Watch the segments covering the basics, from the introduction through the explanation of resources, methods, and responses. This will set the stage for the deeper principles to follow.

As the video explains, an API that adheres to these principles is called "RESTful." Now, let's unpack the most important of those principles.


2. The Core Principles of REST

The power of REST comes from a few key constraints that, when followed, lead to systems that are scalable, easy to understand, and independent.

a) Client-Server and Statelessness

We've already discussed the client-server model. REST builds on this by adding a crucial rule: statelessness. This means that every single request from a client to the server must contain all the information the server needs to understand and process the request. The server does not store any information about the client's session state between requests.

Why is this so important? Statelessness is a key enabler of scalability. Since any server can handle any request (because the request itself is self-contained), you can easily add more servers behind a load balancer to handle increased traffic.

The High-Performance Programming channel has an excellent video that explains this concept and its powerful implications.

Rest API - Best Practices - Design

This video provides a deep dive into the concept of statelessness, explaining its benefits for scalability and availability, and even shows how to handle application state (like a shopping cart) while keeping the API itself stateless.

Watch the section from the beginning until the discussion on statelessness. Pay close attention to the distinction between statelessness in single-server vs. distributed environments.

b) Resource-Based Architecture

This is perhaps the most fundamental mind-shift in REST. Instead of thinking about remote procedures or actions (like getUsers() or createOrder()), REST asks you to think about resources. A resource is any "thing" or concept that can be named and addressedโ€”a user, a product, an order, a collection of orders.

In a REST API, each resource has a unique identifier, which is its URL (or URI). You then use standard HTTP methods to perform actions on these resources. This means your URLs should contain nouns, not verbs.

Let's look at the "RESTful API Design Guide" from Strapi for a detailed explanation.

RESTful API Design Guide: Principles & Best Practices

This guide clearly articulates the resource-oriented approach and provides practical advice on how to structure URLs correctly.

First, read the section Resources Over Actions to solidify the "nouns, not verbs" concept. Then, jump to the section on naming and structuring URLs. This part gives concrete rules: Use plural, lowercase nouns (e.g., /users, /orders). Keep the hierarchy shallow. Use the query string for filtering, sorting, and pagination (e.g., /orders?sort=-created_at).

c) Uniform Interface

The "Uniform Interface" is the central constraint that distinguishes REST. It ensures that every API, regardless of who built it, speaks the same language. This makes APIs predictable and easier for developers to use. This principle is achieved by combining resource-based URLs with the standard HTTP methods and status codes we've already learned.

Let's map the HTTP methods to the common CRUD (Create, Read, Update, Delete) operations that form the basis of most applications.

This table clearly maps HTTP Methods to their corresponding CRUD operations and provides examples of how they are used with resource URLs. Note the properties of 'Safe' (does not change server state) and 'Idempotent' (same effect if repeated).

Here's how it works in practice:

  • To Read data: Use GET.
    • GET /products โ†’ Returns a list of all products.
    • GET /products/123 โ†’ Returns the single product with ID 123.
  • To Create data: Use POST.
    • POST /products โ†’ Creates a new product. The data for the new product is sent in the request body. The server will typically respond with a 201 Created status code and a Location header pointing to the URL of the newly created resource (e.g., Location: /products/456).
  • To Update data: Use PUT or PATCH.
    • PUT /products/123 โ†’ Replaces the entire product with ID 123 with the data in the request body.
    • PATCH /products/123 โ†’ Partially updates the product with ID 123. Only the fields included in the request body are changed.
  • To Delete data: Use DELETE.
    • DELETE /products/123 โ†’ Deletes the product with ID 123. The server will typically respond with 204 No Content.

By strictly following this mapping, your API becomes instantly understandable. Anyone familiar with HTTP can guess how to interact with your resources.

The Postman blog provides a great set of best practices that summarize these points.

REST API Best Practices: A Developer's Guide to Building ...

This article serves as a great checklist for ensuring your API design is clean and conventional.

Quickly review the following sections to reinforce what we've just discussed: Use consistent resource naming Use proper HTTP methods Implement proper status codes


3. A Glimpse at Higher-Level Concepts

While the principles above form the core of REST, there are a couple of other concepts you'll encounter as you progress.

  • API Versioning: What happens when you need to make a breaking change to your API? You can't just change it and break all your existing clients. The common practice is to version the API, usually in the URL: /v1/users, /v2/users. This allows you to support old versions while new clients adopt the latest one.

  • HATEOAS (Hypermedia as the Engine of Application State): This is considered the highest level of REST maturity. It means that a server response should include not just the requested data, but also links to other related actions or resources. For example, a response for an "order" resource might include a link to /orders/123/cancel if the order is cancellable. While powerful in theory, it's complex to implement and not widely used in practice. It's good to know the term, but most commercial APIs you build will be "Level 2" RESTful (following the principles we've focused on today).


Conclusion

In this lesson, we've elevated our understanding from the mechanics of HTTP to the architectural philosophy of REST. You now have the foundational knowledge to design clean, predictable, and scalable web APIs.

Key Takeaways:

  • REST is an architectural style, not a rigid standard, based on a set of guiding principles.
  • Statelessness is a core constraint: every request is independent and self-contained, enabling scalability.
  • APIs should be organized around resources (nouns), not actions (verbs). Resource URLs should be predictable (e.g., /users, /users/{id}).
  • A Uniform Interface is achieved by using standard HTTP methods (GET, POST, PUT, PATCH, DELETE) for CRUD operations and standard HTTP status codes (200, 201, 404, etc.) to communicate outcomes.

We have now completed Module 2, covering your developer environment and the fundamentals of web communication. You understand how to manage your code with Git, create isolated environments, and how clients and servers talk using HTTP and REST.

In the next module, Advanced Python for Backend Systems, we will dive back into Python. We'll explore more advanced features like object-oriented programming, decorators, and error handling that are essential for building the logic inside your Django and DRF applications.