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

How to use CORS with .NET6 minimal APIs?

I have a .NET6 minimal api deployed in Heroku that is returning this following CORS error: Access to XMLHttpRequest at '...' from origin '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested…
lcarvalho
  • 71
  • 1
  • 4
1
vote
2 answers

ASP.NET Core - want to force text/plain with Results.Ok()

Trying to replicate a Framework API using .NET Core 6 and minimal APIs. One thing is I am getting "application/json" as the content-type if I return Results.Ok(data). Yes it should be json, but this is replicating legacy functionality. I can get the…
Daniel Williams
  • 8,912
  • 15
  • 68
  • 107
1
vote
1 answer

I have a problem with Asp.net and MediatR

I'm learning CQRS so I'm using MediatR I've watched videos for demos but I don't understand this line services.AddMediatR(typeof(Startup)); Why did they add to the services container the type of "Startup"? What is exactly the type that should be…
b.g
  • 31
  • 3
1
vote
1 answer

How to Set JSON PropertyNamingPolicy when using Results.OK in Minimal API when JsonSerializerOptions.PropertyNamingPolicy has no effect?

I am using a Minimal API to recreate an old REST service and so I need to mimic the functionality of the previous service as close as possible. Information in the old service is returned Pascal case and I know that there are some old clients that…
1
vote
2 answers

Using request objects for non-body parameters in Minimal API

Is it possible to have a request class where it is possible to declare the minimal API request parameters in .NET 6? I know that a similar feature will be provided by .NET 7. What I am trying to achieve is the following: public class…
ddfra
  • 2,413
  • 14
  • 24
1
vote
1 answer

Resolving dependencies in a Func that is moved to a separate class file

I'm working with a codebase (Minimal APIs : .NET 6) which exposes a custom middleware (UseCustomMiddleware) that is added to IApplicationBuilder via extension methods. The second parameter of UseCustomMiddleware is a Func
wiki
  • 1,877
  • 2
  • 31
  • 47
1
vote
1 answer

Is it possible to use custom RequireAuthorization and AllowAnonymous for custom middleware authentication in ASP Net Core 6 Minimal APIs?

I currently have this web app in which I need to use a custom authentication/authorization middleware. We're registering the routes using minimal APIs like so: // snip app.UseEndpoints(x => { x.MapGet("/api/something", () => { ... returns…
1
vote
1 answer

Unexpected identical object obtained for each http request for scoped service

I have two endpoints: /x that is defined in Endpoint.Register() (Bipin Joshi's approach to organize endpoints) /y that is defined in Main() (the default of minimal api template) As I expect that instances of Endpoint and Foo are different for each…
1
vote
1 answer

Minimal API - 415 error when using multipart/form content type and custom body model

First of all, here is a POST mapping that DOES work : app.MapPost("formulary/uploadSingle/{oldSys}/{newSys}", async (HttpRequest request, string oldSys, string newSys) => { return await…
Martin
  • 1,977
  • 5
  • 30
  • 67
1
vote
1 answer

ASP.NET and integration tests - data returned from WebApplicationFactory is nulled when parsed as JSON

I have a problem with integration test (made with WebApplicationFactory) that cannot parse back to JSON obtained response. I have seen some similar issues reported here but nothing found so far was helpful. Generally, for the test purpose there is…
pklimczu
  • 626
  • 1
  • 6
  • 15
1
vote
1 answer

How to keep ASP.NET Core minimal APIs from returning the full stack trace when there is an error

I am writing an API using ASP.NET core's minimal API setup in C#. How can I keep it from returning the stack trace for internal server errors? For instance, if the below code throws an SQL error while processing the data it gets returned and shows…
TarHalda
  • 1,050
  • 1
  • 9
  • 27
1
vote
2 answers

Passing parameter from MapPost to local function

I was refactoring my endpoints in a Minimal WebApi project and faced this situation: namespace DACRL.API.Endpoints; public class ApiUserManagementEndpoints : IEndpoints { private const string ContentType =…
DoomerDGR8
  • 4,840
  • 6
  • 43
  • 91
1
vote
1 answer

Store arbitrary json in CosmosDB posted into api endpoint

I'm trying to save semi arbitrary json to CosmosDb I say semi because the start of the json will have some known properties. For example: { "id": "88e37e40-fd7e-478e-9ac5-140601fcddad", "type": "http", "name": "request1", "body": { …
Alex
  • 37,502
  • 51
  • 204
  • 332
1
vote
1 answer

Minimal API - Invalid JSONs in request body

I'm facing a behavior in Minimal API that I can't understand.Consider the following simple Minimal API: var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.UseExceptionHandler((exceptionApp) => { …
Farzan Hajian
  • 1,799
  • 17
  • 27
1
vote
1 answer

How to fire a function on every request in .net core minimal API

Just starting out with .net core minimal API and trying to solve all the little issues that will have to work before it's usable in my situation. This API will be accessible from multiple tenants so I need to check the calling domain on every…
Rolf Herbert
  • 45
  • 1
  • 8