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

How to catch BadHttpRequestException thrown by invalid json body

Im playing abit with the .NET minimal API. Trying to catch this exception when Im passing "Price" as a string I've got my DTO as follows: public record TransactionCreateDto { public string Description { get; init; } = String.Empty; …
2
votes
3 answers

How to increase the request size limit using minimal api with .NET 6?

I have an endpoint to upload videos app.MapPost("/video/upload", async (HttpRequest request) => It works with small videos but when I try to upload a video of larger size I get an error saying that I exceeded the allowed size
Careuno Merchan
  • 186
  • 2
  • 9
2
votes
1 answer

Configuring InvalidModelStateResponseFactory with Minimal API

In ASP.NET Core with controllers I was able to customize the error response when a model binding error ocurred by adding the following in Program.cs: builder.Services.Configure(options => { …
sanfalero
  • 372
  • 2
  • 18
2
votes
1 answer

MapGet execution sequence in pipeline

I have 2 pieces of code var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.MapGet("/", () => "Hello World!"); app.Use(async (context, next) => { if (context.Request.Headers["token"] != "my_token") { …
giorgi02
  • 683
  • 6
  • 13
2
votes
0 answers

How to use custom filter in Minimal Api .net 6.0?

After decoding the token generated in another application, I need to check for an expire. I used OnActionExecuting in web app but not working this method in minimal api. Now I'm catching it by checking the response, but I need a better solution than…
2
votes
1 answer

Use of IEnumerable<> and IFormFileCollection, in .NET 6 Minimal API

Problem is, I have an API that concatenates pdfs from Urls, and it's working in .NET 5 , but when starting to migrate to .NET 6, the use of IEnumerable<> , IFormFile, and IFormFileCollection , simply only accepts requests application/json. Here is…
Gean Souza
  • 21
  • 1
2
votes
1 answer

Bad Request (400) for POST request to ASP.NET Core 6, minimal API, sent from Postman

why I get 400 bad request when testing ASP.NET CORE minimal API app with Postman? Default VS 2022 ASP.NET core minimal API project, with following method handler: app.MapPost("/test", (AnalizeSentenceRequest r) => { return Results.Ok($"Echo:…
zizu_zaza
  • 95
  • 1
  • 8
2
votes
1 answer

Cannot add [FromHeader] attribute for a model/class in ASP.NET Core 6.0 minimal api

I'm trying to add multiple custom headers in the .NET core minimal API, so I added [FromHeader] attribute in front of input parameters. It's working fine, I can see those headers in swagger. But I'm looking for a better way to keep all these headers…
Sivashankar
  • 493
  • 1
  • 8
  • 17
2
votes
1 answer

Dynamic delegate to minimal api

Hello fellow programmers. Basically, I want to pass a dynamically built delegate to minimal api MapGet or MapPost method. This is the method that constructs the delegate: private static Delegate GetDelegate(Type type, MethodInfo method,…
Mantas
  • 65
  • 1
  • 6
2
votes
1 answer

MongoDB with .net 6 and BsonDocument fieldtype

I'm trying to retrieve a list of objects from my MongoDB Database. I have to use a BsonDocument to store additional dynamic data on the record, but when I try to return a list to the browser using minimal API I get the following…
Mauricio Sipmann
  • 465
  • 6
  • 21
1
vote
1 answer

ASP.NET Core Web API - InvalidOperationException: Body was inferred but the method does not allow inferred body parameters

I created an ASP.NET Core Web API project with the default Visual Studio template, disabling the configure for https checkmark and whenever I am trying to run my application, I get this error shown here: An unhandled exception occurred while…
1
vote
2 answers

Validate ASP.NET Core Minimal APIs at startup

I am using ASP.NET Core Minimal APIs with .NET 8. I have an application that adds some endpoints. One of these endpoints is not valid, but the app starts normaly: info: Microsoft.Hosting.Lifetime[14] Now listening on:…
mMilk
  • 245
  • 1
  • 2
  • 10
1
vote
1 answer

Default challenge scheme isn't working with RouteGroups?

I have a Route Group for several endpoints: internal class EmployeeRouteGroup : RouteGroup { /// protected override string Prefix => "employees"; /// protected override RouteGroupBuilder…
1
vote
1 answer

How to make enum serialization default to string in minimal API endpoints and Swagger?

I'm working with .NET minimal APIs and have encountered a problem with JSON serialization/deserialization behavior for enums. Despite my attempts to change the behavior to use strings instead of integers, Swashbuckle.AspNetCore's Swagger…
nop
  • 4,711
  • 6
  • 32
  • 93
1
vote
1 answer

Writing & testing a PatchAsJsonAsync request in a .NET 7.0 Minimal API

Writing the Implementation Let's pretend I have a Person object: public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } My…
nathano
  • 21
  • 3