Imagine a restaurant.
- You (the client) sit at the table.
- The menu lists what you can order: burger, fries, milkshake.
- The waiter takes your request to the kitchen (server), brings the food (data) back.
That’s what a REST API is:
- You (the frontend or client app) make requests.
- The server (kitchen) processes them.
- The API (waiter) is how the two communicate.
REST just means:
“Let’s follow some simple rules to communicate over HTTP, using standard methods like GET, POST, PUT, DELETE.”
Core Concepts (And How to Explain Each One Simply)
1. Resources = Nouns
REST is about resources, like:
/books/orders/123/customers/5/orders
Each resource is represented by a URL.
2. HTTP Methods = Verbs
Think of CRUD operations:
| Action | HTTP Method | What it does |
|---|---|---|
| Create | POST | Add a new item |
| Read | GET | Get item(s) |
| Update | PUT / PATCH | Modify item |
| Delete | DELETE | Remove item |
You explain it like this:
“We use HTTP methods to tell the server what we want to do to a resource — like reading a book list (GET /books) or deleting a book (DELETE /books/3).”
3. Statelessness
Every request is independent.
“Imagine if the waiter forgot your last order. Every time, you have to tell them everything again. That’s stateless — REST APIs don’t remember anything between calls.”
4. JSON as the Common Language
Most REST APIs use JSON to send data back and forth.
“It’s like saying: we’ll all speak the same simple language — like JSON — to describe things like a book or a user.”
json{
"id": 1,
"title": "Atomic Habits",
"author": "James Clear"
}
How You Build a REST API in .NET
Let’s go step-by-step using an example:
Goal: Build a REST API to manage books.
Step 1: Create a Controller
C# Code[ApiController]
[Route("api/[controller]")]
public class BooksController : ControllerBase
{
private static List<Book> books = new List<Book>();
[HttpGet]
public ActionResult<List<Book>> GetAll() => books;
[HttpGet("{id}")]
public ActionResult<Book> GetById(int id) =>
books.FirstOrDefault(b => b.Id == id);
[HttpPost]
public IActionResult Create(Book book)
{
books.Add(book);
return CreatedAtAction(nameof(GetById), new { id = book.Id }, book);
}
[HttpPut("{id}")]
public IActionResult Update(int id, Book updated)
{
var book = books.FirstOrDefault(b => b.Id == id);
if (book == null) return NotFound();
book.Title = updated.Title;
return NoContent();
}
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
var book = books.FirstOrDefault(b => b.Id == id);
if (book == null) return NotFound();
books.Remove(book);
return NoContent();
}
}
Now Practice Round: You Teach Me
Now try this, imagine I’m your junior teammate or interviewer. Teach me:
“What is a REST API and how does it work in C#?”
Give it a shot in your own words in the comments below, then I’ll give you friendly feedback and help you make it even clearer.
