In this article, we'll explore how to leverage the Endpoints Explorer in a .NET 8 Minimal API application for debugging and sending requests. We'll create a simple API that receives a string called name
and returns a hello message.
Sample Minimal API Code
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IMessageService, MessageService>();
var app = builder.Build();
app.MapGet("/", (string name, IMessageService service) => service.Get(name));
app.Run();
public interface IMessageService
{
string Get(string name);
}
public class MessageService : IMessageService
{
public string Get(string name)
{
return $"Hello {name}!";
}
}
Steps to Leverage Endpoints Explorer
Step 1: Open Endpoints Explorer
- Navigate to
View -> Other Windows -> Endpoints Explorer
or use the shortcutAlt + E, Alt + E
. - In the Endpoints Explorer, expand and select the
GET
endpoint with the path/
..
Step 2: Generate .http file
- Right-click on the selected endpoint.
- Choose
Generate request
option from the context menu. This action will generate an associated.http
file containing the details of the request. - Edit the generated
.http
file to send a sample request with thename
parameter.
Step 3: Set Breakpoints in the Method
- Open the
Program.cs
. - Locate the
Get
method. - Set a breakpoint at the beginning of the
Get
method. This will pause the execution of the code when the breakpoint is hit during debugging.
Step 4: Debug from the .http File
- Navigate to the generated .http file.
- Click on the "Debug" option within the file. This will trigger the API request associated with the endpoint.
- Observe the debugger will hit the breakpoint in the method.
This article demonstrates the power of Endpoints Explorer in debugging and testing your .NET 8 Minimal API applications. Understanding how to use these tools is essential for efficient development and troubleshooting.