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

return a Tuple from minimal API

I'm trying to return a Tuple in a minimal API, it boils down to this: app.MapPost("/colorkeyrect", () => server.ColorkeyRect()); public (int x, int y, int w, int h) ColorkeyRect() { return (10, 10, 10, 10); } But the data that is sent over the…
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98
0
votes
1 answer

GetEndpoint from Middleware returns 405 HTTP Method Not Supported when launching from integration test

I'm using an ASP.NET minimal API which works fine when launching normally, but when I try to reuse the Program class from my integration tests there is one endpoint that fails in a custom middleware. I used the trick from…
dakotapearl
  • 373
  • 1
  • 15
0
votes
1 answer

In ASP.NET Core minimal API, how can you get the route name?

I would like to test the routing of a minimal API WebApplication. How can I get the route name, given a HttpRequestMessage? var builder = WebApplication.CreateBuilder(args); builder.Services.AddRouting().Configure(options => {}); var…
Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70
0
votes
1 answer

Minimal API with Azure Application Settings

I cannot get my application settings or connections from Azure Web App update my .net 6.0 minimal api. I've tried using environment variables but that only tells me there's a string value. I've also tried using other methods such as the normal way…
0
votes
1 answer

Minimal API - How to use ILogger in static class

I created the following class: public static class PingEndpoints { public static void Endpoints(this WebApplication application) { var group = application.MapGroup("ping"); group.MapGet("", PingMethod); } internal…
Hardipsinh Jadeja
  • 1,180
  • 1
  • 13
  • 30
0
votes
1 answer

FromBody attribute not working for app.MapPost

I have a form posting to endpoint /api/vendors/add. when I submit the form it gives me the error, This page isn’t working If the problem continues, contact the site owner. HTTP ERROR 415 when I remove the param it works just fine. What am I doing…
eleethesontai
  • 454
  • 5
  • 19
0
votes
0 answers

Extend default authorization policy - is it possible?

Currently I'm using .NET 7 with Minimal API. I've created several methods in WebApplicationBuilder extension class, for Default policy set: private static void AddDefaultAuthorization(this WebApplicationBuilder builder) { …
0
votes
1 answer

Why is .NET 6 minimal API returning JSON as a string and not as JSON?

I have a minimal API in .NET 6. In this API, I call a 3rd party API which returns normal json formatted data by using this code: HttpResponseMessage response = await client.GetAsync(url); if (response.IsSuccessStatusCode) { jsonResponse = await…
John
  • 29
  • 3
0
votes
1 answer

Is there a way to configure the serialization response in a minimal C# API?

I tried using the following line builder.Services.Configure(options => options.Converters.Add(new JsonStringEnumConverter())); to configure that the enums are converted to string when returning return Results.Ok(new…
user33276346
  • 1,501
  • 1
  • 19
  • 38
0
votes
0 answers

Is it possible to use Newtonsoft JSON in minimal API instead of System.Text.Json?

I use .NET 7 Minimal API (app.MapGet) but I can't figure out how to use Newtonsoft instead of System.Text.Json. I tried... builder.Services.AddMvc().AddNewtonsoftJson(); And…
MojoDK
  • 4,410
  • 10
  • 42
  • 80
0
votes
2 answers

How to access HttpContext from IRequestHandler using Mediator - Minimal API (C#)

Is there a way to access HttpContext from a request handler? I added a filter to my (minimal API) endpoint to validate the API key, coming from the request headers. Upon successful validation I need the value to Generate JWT for subsequent…
Aweda
  • 323
  • 1
  • 4
  • 15
0
votes
1 answer

Can WireMock conditionally change authorization header for integration test?

I'm doing (learning about) integration testing on my web api. One of my web api methods calls out to EXTERNAL web service that takes Basic authorization. So, I've intercepted my external web api call via WireMock with the following code in my…
Terry
  • 2,148
  • 2
  • 32
  • 53
0
votes
1 answer

Minimal API return result with StatusCode and Problem

The convention in our microservices is to return the result as follows: return result.StatusCode == (int) HttpStatusCode.Created ? StatusCode(result.StatusCode, result.MessageCode) : Problem(result.MessageCode,…
Lorena Sfăt
  • 215
  • 2
  • 7
  • 18
0
votes
1 answer

EFCore DbContext OnConfiguring not called for second sql server db context in minimal api

I have a minimal api project that works with a single DBContext for one SqlServer db that is in a separate EFCore project. I've added a second GFContext to the EFCore project. When I attempt to access an entity in the new GFContext, the protected…
0
votes
1 answer

.net 7 Route Handling and Parameter Binding in minimal apis

I had asked this question on Regex parsing with multiple named groups. This is the original problem that motivated that question and is an orthogonal problem. In .net 7, using the minimal apis is there a way to map multiple key-value pairs that…
vvg
  • 1,010
  • 7
  • 25