Questions tagged [minimal-apis]

Minimal APIs were introduced in ASP.NET Core 6 and are architected to create HTTP APIs with minimal dependencies. They are ideal for microservices and apps that want to include only the minimum files, features, and dependencies in ASP.NET Core.

Minimal APIs were introduced in ASP.NET Core 6 and are architected to create HTTP APIs with minimal dependencies. They are ideal for microservices and apps that want to include only the minimum files, features, and dependencies in ASP.NET Core.

Answers for many question can be found in the documentation.

236 questions
2
votes
1 answer

Separate Program.cs to Startup.cs in ASP.NET WebAPI Minimal for Integration testing

I am trying to write integration tests for my web service. I want to separate Program.cs into Startup.cs so test class can mock TestStartup.cs(or something like so). The point is swapping real services with mock services. Attempt to use Startup.cs…
2
votes
1 answer

Getting the request body as a string in and EndpointFilter .Net 7

I created a simple endpoint filter on a C# minimal api and when I try to get the body into a string it is always blank. app.MapPost("/todo", async (Todo todo) => { await Task.Run(() => { string x = "R";}); return…
2
votes
1 answer

Minimal API Results.Ok Not Returning Full Object

While working on a larger Minimal API project, Results.Ok() was not returning the full object. However, switching to Results.Text() returns the full object. I've included the full listing of a simple application that I created to see if I can…
2
votes
1 answer

MinimalAp IEndpointFilter MapGet Get Pattern

In the IEndpointFilter would like to get the route used. app.MapGet("/get/{productId:guid}", ...... public class MyFilter : IEndpointFilter { public async ValueTask InvokeAsync(EndpointFilterInvocationContext context,…
Kazmir
  • 25
  • 4
2
votes
1 answer

Resolving a DI error with Mediatr and .NET Core 7 Minimal APIs

I am currently getting a DI related error message when I try to run my minimal API app with the following classes. Any help would be greatly appreciated. Endpoint public static void DefineEndpoints(IEndpointRouteBuilder app) { …
dmeadley
  • 77
  • 5
2
votes
1 answer

HEAD Verb in Minimal API C#

HEAD The HTTP HEAD method requests the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET method. For example, if a URL might produce a large download,a HEAD request could read its Content-Length header…
TheSloth
  • 23
  • 4
2
votes
1 answer

ASP.NET Core Minimal API not picking up request headers when hosted on VM

So I'm running a Linux VM (DigitalOcean Droplet) to host my ASP.NET Core Minimal API, I've got one endpoint that requires a refresh token to be supplied in the header and have done so using the following parameter/annotation in the MapPost…
2
votes
1 answer

Do we really need app.Run(); in a minimal Web API?

So I've been studying the documentation of.net Core Middleware and it mentions there are three types of request delegates: Run, Use and Map. I use app.MapGet() to handle a few specific routes and I have a few app.Use() to filter some incoming…
Wim ten Brink
  • 25,901
  • 20
  • 83
  • 149
2
votes
1 answer

Minimal API with async static method

When we create something like this in NET 7: app.MapPost("/test", SomeEndpoint.Test); This is my SomeEndpoint.Test: public static class SomeEndpoint { public static IResult Test(HttpContext httpContext) { var form =…
Szyszka947
  • 473
  • 2
  • 5
  • 21
2
votes
2 answers

Making use of Filters in .NET 7

I have been using Minimal APIs since it was released in .NET 6. For our validation I've been using the manual approach as follows: app.MapPost("api/user", async ([FromService] IValidator validator, [FromBody] UserDto user) => { var…
Izzy
  • 6,740
  • 7
  • 40
  • 84
2
votes
1 answer

Using MapGroup with minimal APIs in .NET 7

I've tried to use the .NET 7's minimal API, I think it's a great thing from the .NET team my only concern was about the medium / Large applications that contain a lot of end-points with different logic So, how to group my controller's logic without…
esamaldin elzain
  • 320
  • 1
  • 4
  • 16
2
votes
1 answer

POST request return empty response

I've got a minimal API with a POST request /query expecting a raw json to search in mongodb app.MapPost("/query", async (HttpContext context) => await FreeQuery(context)); FreeQuery is async and it returns an IEnumerable. But the async version…
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98
2
votes
1 answer

Minmal API DI reconstructs dependencies even when registered as singleton

Started working on a windows background service in .net that will host a restful service. As I worked on it, it seemed like Minimal APIs were a good fit (it was one of the things I was able to get a working prototype with, I couldn't get other stuff…
2
votes
2 answers

Scaffolding Minimal Api with a separate DbContext project throws error "Could not load information for ..."

I have a solution name BugDemo consisting of 2 projects. Here is the github repo. a class library named Data. an Asp.Net Core Minimal Api named Api referencing Data project. I set Api project as the startup project. I use User Secret to share…
2
votes
2 answers

How to add AllowAnonymous when using MinimalAPIs?

How to allow anonymous access to an endpoint when using MinimalAPIs? Assume I have the code below in the Program.cs file of a web app, using the Minimal API syntax: app.MapGet("/hello", () => "world"); When using non-minimal syntax, we could allow…
derekbaker783
  • 8,109
  • 4
  • 36
  • 50