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
4
votes
1 answer

Swagger UI and Swagger Doc does not generate query string. .NET 6 Web API with Minimal API, Mediatr, and Swashbuckle

I have build a Web API application using .NET 6, Mediatr, and Swashbuckle ASPNetCore. I am using nTier structure, so there is more than one project for my solutions with my Web API project having reference to a class library project that consist…
4
votes
1 answer

Is it possible to use AspNet Api Versioning with Net 6 Minimal APIs?

I am using Net 6 Minimal APIs: application.MapGet("countries", async (IService service) => { var countries = await mediator.Send(request); return Results.Ok(countries); }); Is it possible to use AspNet Api Versioning with Net 6 Minimal APIs?…
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
3
votes
1 answer

How to return chunked text/plain content from Web API using minimal API

Using an ASP.NET Core 6 Web API written in C# with minimal API, I would like to return a stream of data without first loading the data into memory. In my case this is JSONL (JSON lines) data that is written by Apache Spark. JSONL is a text-based…
Morrolan
  • 317
  • 3
  • 10
3
votes
1 answer

Asp.NET Core 7.0 Minimal API: OpenAPI how to specify correct DateOnly type representation

In minimal API I define this endpoint that accepts DateOnly parameter: app.MapGet("/info", (DateOnly date) => $"{date.ToString("yyyy-MM")}"; By default swagger json is generated with parameter schema as string: "/info": { "get": { "tags": [ …
joostas
  • 485
  • 5
  • 10
3
votes
1 answer

How to reference IResult in ASP.NET Core 7

I've created a minimal web API in .NET 7 and I am trying to extract some of the code to a separate assembly. This code is using IResult, which was introduced in .NET 7. How do I reference IResult from a regular class library? According to MSDN, the…
Reyhn
  • 997
  • 1
  • 11
  • 22
3
votes
1 answer

.NET Core 7 Minimal API MediatR IRequest Handler mapping error

I am currently getting the following error when executing a command via .NET Core 7 Minimal API: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. …
dmeadley
  • 77
  • 5
3
votes
1 answer

Open Telemetry with .Net 7 minimal api - AttachLogsToActivityEvent not working with 'IncludeFormattedMessage'

I am using 'OpenTelemetry.Contrib.Preview' package to attach ILogger standalone logs as Activity Events (aka Trace events) to co-relate the logs with trace & show at a single place like Jaeger. As part of the documentation if we want to attach the…
SanjayD
  • 156
  • 4
  • 12
3
votes
1 answer

Comparing the size of minimal and controller based APIs in .NET

Is the ASP.NET Core 6 minimal API supposed to create a smaller app compared to the classic controller based approach? From the Microsoft documentation Minimal APIs are architected to create HTTP APIs with minimal dependencies. They are ideal for…
Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55
3
votes
0 answers

Weird exception when parsing form files minimal api .net 6

i'm sending some pdfs trough form-data bodytype to my minimal api in .net 6 and sometimes i encounter a weird exception. i try to read my files from the HttpRequest class like so: HttpRequest rq var uploads = rq.Form.Files ?? throw new…
dperic00
  • 31
  • 2
3
votes
2 answers

Custom Authorization Filtering Minimal API .Net 6

I'm exploring Minimal APIs in .Net 6, and trying to apply a custom Authorization Filter to the endpoint (via Attributes or Extensions). But it seems to me, I am doing something wrong, or it's simply not designed to work in that way (and it's sad if…
Beeeg
  • 33
  • 1
  • 4
3
votes
2 answers

How do you sort endpoints in swagger with the minimal api .net 6

I am trying to get the hang of swagger in minimal API. I have the following code: builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(setup => setup.SwaggerDoc("v1", new OpenApiInfo() { Description = "An api that will…
3
votes
1 answer

Override Host configuration in Integration Testing using ASP NET Core 6 Minimal APIs model

Being able to customize the Host configuration in integration tests is useful to avoid calling services that shouldn't run at all during testing. This was easily achievable using the standard Startup model, overriding the CreateHostBuilder from the…
Mahmoud Ali
  • 1,289
  • 1
  • 16
  • 31
3
votes
1 answer

Accept x-www-form-urlencoded in Minimal API NET 6

I'm trying to send a "Content-Type" header: "application/x-www-form-urlencoded" to a minimal api and I get the following error: Microsoft.AspNetCore.Http.BadHttpRequestException: Expected a supported JSON media type but got…
3
votes
0 answers

Minimal Api byte[] parameter binding problem

If pass a byte array as parameter to a minimal api endpoint, like : app.MapGet("api/srv/myget", [FromQuery] byte[] data) => DoSomethingWith(data); then when I try tu run it throws an exception with: No public static bool byte[].TryParse(string,…
jeprato
  • 61
  • 1
  • 6
3
votes
1 answer

How Can I Render CSHTML From A MapGet Route (ASP.NET Core)?

I'm developing an ASP.NET Core project and I'm trying to do dynamic routing, so if I go to /page/[str] it returns something custom depending on [str]. I can return a string like so: app.MapGet("/page/name:alpha", (string name) => { return…
1
2
3
15 16