Skip to content

Module 1: ASP.NET Core Web API (The Distribution Center)

📚 Module 1: ASP.NET Core Web API

Course ID: DOTNET-401
Subject: The Distribution Center

A Web API is like a website, but instead of sending beautiful HTML pages, it only sends raw Data (JSON). This allows any app (Mobile, React, Blazor) to use your data.


🏗️ Step 1: RESTful Services (The “Vending Machine”)

Web APIs usually follow the REST pattern.

🧩 The Analogy: The Vending Machine

  1. GET: You look through the glass to see what’s inside. (Read Data).
  2. POST: You put money in to get a new item. (Create Data).
  3. PUT: You replace a broken spring in the machine. (Update Data).
  4. DELETE: You remove a snack that is expired. (Delete Data).

🏗️ Step 2: JSON (The “Universal Language”)

Since your API doesn’t know who is calling it (a iPhone? a Web browser?), it speaks a universal language called JSON.

🧩 The Analogy: The Telegram

  • JSON is just text that looks like a list:
{
  "id": 1,
  "name": "Laptop",
  "price": 999.99
}

🏗️ Step 3: Swagger (The “Menu”)

A Senior .NET Developer uses Swagger (OpenAPI) to automatically document their API.

🧩 The Analogy: The Digital Menu

  • Instead of telling developers “Here is a list of my 50 endpoints,” Swagger builds a website where they can click “Try it out” and see exactly how your API works.

🧪 Step 4: Your First API Controller

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase {
    
    // GET: api/products
    [HttpGet]
    public IEnumerable<string> Get() {
        return new string[] { "Laptop", "Mouse", "Keyboard" };
    }
}

🥅 Module 1 Review

  1. Web API: A backend that only sends Data, not HTML.
  2. HTTP Verbs: GET (Read), POST (Create), PUT (Update), DELETE (Delete).
  3. JSON: The text format used to share data.
  4. Swagger: The automated documentation for your “Distribution Center.”