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
1
vote
1 answer

C# Minimal API Agents

I am trying to run multiple versions of a C# minimal API as agents. The logic being that I will programatically create multiple versions of my minimal API but each with a different port. The manual way of doing this would be to run: dotnet…
1
vote
2 answers

Make a parameter in minimal api as an optional in .NET Core

I have this API as you can see: app.MapGet("/api/fund/{fundCode}", ([FromServices] IMediator mediator,string fundCode) => mediator.Send(new GetFundsQuery(fundCode))); I want to set fundcode as an optional parameter to my API, so I changed it…
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
1
vote
1 answer

Automatic registration of API enpoints in .Net Core Minimal Api

I have the base class that I’m using for internal communication in my app. public abstract class EndpointBase where TRequest : class, IRequest where TResponse : class { public abstract bool…
1
vote
0 answers

What is the most universal way to get metadata about defined endpoint parameters?

We can define that some of the endpoint parameters should be bound from query string: [FromQuery(Name= "someParamName")]. Is this mapping information stored anywhere in endpoint metadata? I want to ensure that passed query string parameter is…
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
1
vote
1 answer

.NET 6 Minimal APIs with Role Based Authorization Error System.NotSupportedException: Serialization and deserialization of 'System.Func`

Trying to add role authorization to minimal api and I dont understand why this simple test is not working. I can confirm that the role works. In my Program.cs I have app.ConfigureApi(); in Api.cs public static class Api { public static void…
causita
  • 1,607
  • 1
  • 20
  • 32
1
vote
1 answer

Asp.net Minimal API find by username(string)

I want to create endpoint which return the data by username(string). Finding by id is working. It list the data with the given id. app.MapGet("/store/{id}", async (StoreDb db, int id) => await db.Stores.FindAsync(id)) …
jsancho
  • 55
  • 4
1
vote
1 answer

Minimal API Registering Dependencies

I am trying to register dependencies but one thing that is strange is when using specific handlers. For example, take a simple scenario like: using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); var app =…
Dr Schizo
  • 4,045
  • 7
  • 38
  • 77
1
vote
2 answers

MinimalAPI Action filter never get executed

I am working on a minimal API and I am trying to make an actionfilter for authentication works with it. I tried to add my action filter directly on the endpoint registration likeso: app.MapGet("/Users/{userId}",…
1
vote
3 answers

Get a response value out of an IResult in ASP.Net's minimal API

I'm porting a project to the new minimal api of ASP.Net 6. Right now I have something similar to this: builder.MapGet("/hello", CiaoCiao); IResult CiaoCiao() { return Results.Ok("Ciao ciao!"); } The reason for having the endpoint…
Giacomo d'Antonio
  • 2,215
  • 3
  • 19
  • 23
1
vote
2 answers

How do I resolve this error in .NET Minimal API integration with PostgreSQL?

I am trying to make APIs using ASP.Net Minimal API thingy and I am trying to use PostgreSQL as Database so for that I am following an Article and and I have followed it so far but I am unable to get desired output. I have provided all the files…
D_Gamer
  • 168
  • 12
1
vote
1 answer

How a Web API knows the client Culture/Language

We have a new GET service endpoint which expects DateTime and Decimal data, among other parameters. For simplicity, this represent our request without any fix yet: app.MapGet("saleEvent", async (string amount, string date) => { …
zameb
  • 705
  • 11
  • 26
1
vote
1 answer

How to serve video file / stream from ASP Net Core 6 Minimal API

I was trying to achieve this following different tutorials but did not succeed. How do I handle a http range request in minimal API to serve video stream ? I have this bare minimal setup code for API with a single GET path "/video" mapped. I also…
Jeekim
  • 543
  • 5
  • 15
1
vote
2 answers

Why does 'foo' return an empty body?

For some reason, foo always returns an empty body: internal static async Task Foo(HttpContext context) { var response = await Task.Run(() => { return "response"; }); return response; } internal static async Task
Pete rudensky
  • 404
  • 1
  • 5
  • 9
1
vote
1 answer

Can I create an object from the DI container/Lamar in .NET 6.0 minimal hosting, preserving singletons?

We have migrated from a windows Framework 4.7 application to .NET 6.0. Lamar is added for Dependency Injection. We are trying to finalize a refactor to the latest "one-file" program.cs but are getting unexpected System.ObjectDisposedException:…
1
vote
0 answers

Minimal APIs NUnit test: missing testhost.deps.json

In my .NET6 project, I have some minimal APIs and I want to test them. You find the full source code on GitHub. For that, I created a new NUnit test project. In the project file, I added PreserveCompilationContext and the file looks like
Enrico
  • 3,592
  • 6
  • 45
  • 102