Defining HTTP Endpoints in ASP.NET Core
Introduction
Welcome to the course "Creating a REST API with Minimal APIs"! This is the second course in our course path on building minimal API applications with ASP.NET Core. In the first course, you learned the basics of ASP.NET Core, got familiar with its project structure, understood the concept of middleware, learned how to handle exceptions, and created your first minimal API application with a single GET endpoint. In this course, we will dive deeper into defining and handling API endpoints. By the end of this course, you will have a functional minimal API application that allows you to manage your To Do list: adding, retrieving, updating, and deleting tasks. This lesson specifically focuses on defining endpoints for various operations on ToDo items. Let's dive in!
What is REST?
Representational State Transfer (REST) is a simple yet powerful way to design communication between computers over the internet. Think of it as a set of rules that helps computers talk to each other clearly, using the web. REST uses HTTP, the same protocol that your web browser uses to look at websites.
In REST, resources like your to-do list items are identified by URLs. For instance:
- A URL like
http://example.com/todo/1might represent the first item on your to-do list. - Another URL like
http://example.com/todo/2could represent the second item.
The URL points to a specific resource, while the method (or HTTP verb) specifies the operation to be performed on that resource.
HTTP Verbs Overview
To interact with a web API and perform operations on resources identified by URLs, you use HTTP verbs. These verbs define the type of operation you are performing. The most common HTTP verbs and their corresponding ASP.NET Core methods are shown in the table below:
| HTTP Verb | ASP.NET Core Method | Expected Operation |
|---|---|---|
| GET | MapGet | Retrieve data |
| POST | MapPost | Create new data |
| PUT | MapPut | Update existing data |
| DELETE | MapDelete | Delete data |
| PATCH | MapPatch | Partially update data |
Although PATCH is included for completeness in this lesson, we will not be practicing it in this course since it is less frequently used compared to the other methods.
