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
3
votes
2 answers

.net 6 minimal api docker issue: error CS5001: Program does not contain a static 'Main' method suitable for an entry point

I have seen a number of similar questions but none seem to represent exactly the issue I am facing. When I create a folder structure as follows: ./ ./src ./src/test Then navigate to ./src/test and run dotnet new webapi -lang c#, this will create a…
WhiteWaterCoder
  • 119
  • 2
  • 7
2
votes
1 answer

.NET 7/8 How do I provide a description/summary on a Group with Minimap APIs?

I am adding a group of minimal APIs like this: var myapi = app.MapGroup("myapi").WithTags("My API").WithOpenApi(); // and then myapi .MapGet($"/", GetAllStuff).WithName("GetAllStuff"); myapi .MapGet($"/{id}",…
user479338
  • 31
  • 3
2
votes
3 answers

This .NET 7 minimal API always returns 200

I'm quite new to the concept of a minimal API, but the documentation seems quite clear. You only have to use Results or TypedResults to return the response code you want. So I made a very basic try: app.MapPost("/api/test", async context => { …
Patrice Cote
  • 3,572
  • 12
  • 43
  • 72
2
votes
1 answer

Minimal API Service not injected using .NET Carter

I´m creating an API in .NET using Carter. I have this Module Defined: public class VariationsModule : EntityModule { public VariationsModule() { this.MainRoute = "api/variations"; } …
2
votes
1 answer

ASP.NET Core Mimal APIs - AddEndpointFilter throws InvalidOperationException

AddEndpointFilter throws exception shown below in .NET 7 (7.0.102) at program start under debug. Used IDE Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.6.3 System.InvalidOperationException HResult=0x80131509 Message=A…
beda
  • 31
  • 5
2
votes
1 answer

IExceptionFilter in minimal .NET 7 API

In my ASP.NET Core app I was registering an IExceptionFilter to globally catch exceptions and replace the Result returned to the client. I'm now switching to the minimal API way of doing things, but I'm not finding where I register that filter. In…
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
2
votes
1 answer

CS8602 error stopping me from running Minimal API image uploader

I am trying to build an image uploader in a .NET 6 Minimal API. I believe that i have all the proper components but I am utterly confused on the problem that I am having. One specific line in the code has a CS8602 error stopping me from running the…
2
votes
1 answer

How to add example responses in Swagger in a ASP .NET minimal API?

I would like to add examples of answers for my endpoints in my minimal API in .NET 7. I have already found several interesting resources but none of them work in the context of a minimal…
heexos
  • 33
  • 4
2
votes
1 answer

.NET Minimal API: how to map all route and all verb in the same handler?

Our team maintains a huge repository containing multiple applications that have been started more than 10 years ago. The strategy at that time was to create classes that implement IHttpHandler and the method public void ProcessRequest(HttpContext…
Tom Sawyer
  • 835
  • 2
  • 10
  • 32
2
votes
1 answer

Streaming data using HotChocolate GraphQl for .NET project - all results at once instead of one by one problem

I'm using C#, .NET7 minimal API and HotChocolate GraphQl. I'm trying to setup graphQl simple query endpoint which will be able to return stream like this: public async IAsyncEnumerable GetDummyNumbers() { for (var i = 0; i < 10; i++) …
Rafp
  • 41
  • 4
2
votes
1 answer

What is the correct lifetime for classes used to organize Minimal Api endpoints and should I resolve them in CreateScope()?

I am still learning and afraid of captive dependency (a dependency with an incorrectly configured lifetime). Consider the following code snippet and the full code is given at the bottom. My objectives: organize Minimal Api endpoints with endpoint…
2
votes
1 answer

Register minimal API IEndpointRouteBuilder with Scrutor

I have created an Interface. public interface IEndpoint { RouteGroupBuilder MapRoutes(IEndpointRouteBuilder rotues); } And it's implementation like this. public class TodoApi : IEndpoint { public RouteGroupBuilder…
2
votes
1 answer

Minimal Api Generic CRUD with dynamic endpoint mapping

I'm trying to automate the implementation of the CRUD for my application. I'm using the Minimal API design, and I wrote a ICrudService which can Get, Single, Add, Update and Delete the T Entity. Now I'm trying to automate the endpoints part. I'm…
M. Ozn
  • 1,018
  • 1
  • 19
  • 42
2
votes
2 answers

Remove all default logging from Minimal Web API C# .NET

Is it possible to remove all logging from the minimal web api? I searched for it and my code currently looks like this: builder.Services.AddLogging(b => { b.ClearProviders(); }); This almost works for everything besides the startup message seen…
Marvin
  • 37
  • 1
  • 3
2
votes
1 answer

FluentValidation validate automatically the request .NET 7 Minimal API

I'm using FluentValidation 11.5.1. I don't want to use: // MapPost // public static void AddUser([FromBody] UserRequest, [FromServices] IValidator validator) I want it to be automatic: public static void AddUser([FromBody]…
1 2
3
15 16