ASP.NET Core Web API Introduction
Before writing a single line of code, it is important to understand what a Web API actually is and why ASP.NET Core is one of the most popular frameworks to build one. This topic lays the foundation for every concept that follows in this course.
What Is an API?
API stands for Application Programming Interface. In simple terms, an API is a messenger. When a mobile app, a website, or any software wants data or wants to send data, it talks to an API. The API processes the request and returns a response.
Think of a restaurant. The customer (client) does not walk into the kitchen. Instead, a waiter (API) takes the order, goes to the kitchen (server/database), and brings back the food (response). The customer never needs to know how the food was prepared.
| Role | Restaurant Analogy | Software World |
|---|---|---|
| Client | Customer | Mobile App / Browser |
| API | Waiter | ASP.NET Core Web API |
| Server / DB | Kitchen | Database / Business Logic |
| Response | Food on the table | JSON Data |
What Is a Web API?
A Web API is an API that works over the internet using the HTTP protocol. HTTP is the same protocol your browser uses to load web pages. A Web API accepts HTTP requests (like "give me a list of books") and sends back HTTP responses (usually in JSON format).
JSON (JavaScript Object Notation) is just a way to represent data as text so any programming language can read it. Here is an example of what a Web API response looks like:
{
"id": 1,
"title": "Clean Code",
"author": "Robert C. Martin",
"price": 29.99,
"category": "Technology",
"isAvailable": true
}
This is a JSON response for one book. Any app — Android, iOS, React, Angular, or even another server — can read this and display it to the user.
What Is ASP.NET Core?
ASP.NET Core is a free, open-source, cross-platform framework built by Microsoft for creating web applications and APIs. It runs on Windows, Linux, and macOS. It is fast, modern, and production-ready.
The word "Core" means it is the modern version of the older ASP.NET framework. ASP.NET Core was rewritten from the ground up to be lightweight and high-performance.
Why Use ASP.NET Core for Web API?
| Feature | What It Means |
|---|---|
| Cross-platform | Works on Windows, Linux, and macOS |
| High performance | One of the fastest web frameworks available |
| Built-in Dependency Injection | Manage services and dependencies cleanly |
| Middleware pipeline | Process requests in a flexible, layered way |
| Built-in JSON support | Automatically converts objects to JSON and back |
| Free and open-source | No licensing cost, huge community support |
| Swagger integration | Auto-generate API documentation |
Web API vs MVC – What Is the Difference?
Both ASP.NET Core MVC and ASP.NET Core Web API are used to handle HTTP requests. The key difference is in what they return.
| Feature | ASP.NET Core MVC | ASP.NET Core Web API |
|---|---|---|
| Returns | HTML Views (web pages) | JSON / XML data |
| Client | Browser only | Any app (mobile, web, desktop) |
| Use Case | Server-rendered websites | Data-driven APIs |
| Base Class | Controller | ControllerBase |
When the goal is to build a backend that serves data to a React frontend, a Flutter mobile app, or even another API, a Web API is the right choice.
How Does a Web API Request Work?
The flow of a request through an ASP.NET Core Web API looks like this:
| Step | What Happens |
|---|---|
| 1 | Client (browser/app) sends an HTTP request to a URL |
| 2 | ASP.NET Core receives the request through the web server (Kestrel) |
| 3 | The request passes through the Middleware pipeline |
| 4 | The Router matches the URL to the correct Controller and Action |
| 5 | The Action method runs the business logic |
| 6 | A response (JSON data) is sent back to the client |
Client
|
| HTTP Request: GET /api/books
v
[ Kestrel Web Server ]
|
v
[ Middleware Pipeline ] → Authentication, Logging, Error Handling
|
v
[ Router ] → Matches /api/books → BooksController → GetAll()
|
v
[ Action Method ] → Reads from Database
|
v
[ HTTP Response: 200 OK + JSON ]
|
v
Client receives book list
What Will Be Built in This Course?
This course builds a BookStore API from scratch. The API manages books in a bookstore. It starts with a simple in-memory list and grows into a fully featured API with a real database, authentication, caching, testing, and deployment.
The Book entity used throughout the course:
Book
├── Id (int) → Unique number for each book
├── Title (string) → Book name, e.g., "Clean Code"
├── Author (string) → Author name, e.g., "Robert C. Martin"
├── Price (decimal) → Price, e.g., 29.99
├── Category (string) → Genre, e.g., "Technology"
├── IsAvailable (bool) → true if in stock, false if not
└── CreatedDate (DateTime) → Date the book was added
Key Points
- An API is a messenger between a client and a server.
- A Web API works over HTTP and returns data (usually JSON) instead of HTML pages.
- ASP.NET Core is a cross-platform, high-performance framework by Microsoft.
- Web API uses
ControllerBase, notController, because it does not return views. - The BookStore API will be built step by step throughout this entire course.
