Looks like following two are working:
app.UseRouting();
// http://localhost/apple
app.UseEndpoints(endpoints =>
{
endpoints.Map("/apple", async context =>
{
await context.Response.WriteAsync("this is an apple");
});
});
// http://localhost/orange
app.Map("/orange", orangeApp =>
{
orangeApp.Run(async context =>
{
await context.Response.WriteAsync("this is an orange");
});
});
What's the difference between these two ways of mapping?
app.Map doesn't use routing, it's a starts with simple string comparison. The order of the middleware is important, there's no composition model (maps run in order) and there's no support for parameters or more complex filtering logic.
The other Map (endpoint routing) is the routing system so it composes with other routes registered. This supports parameters, ordering, constraints and other extensibility. Read more about routing here https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With