373 questions
0
votes
1
answer
810
views
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 ...
3
votes
1
answer
840
views
How to reference IResult in ASP.NET Core 7 [duplicate]
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 ...
7
votes
2
answers
5k
views
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");
...
4
votes
1
answer
3k
views
Minimal Api Generic CRUD with dynamic endpoint mapping
I'm trying to automate the implementation of the CRUD for my application.
I'm using the Minimal API design, and I wrote a ICrudService<T> which can Get, Single, Add, Update and Delete the T ...
2
votes
1
answer
1k
views
How to send a file to a client using a Minimal API? [duplicate]
I wish to send a file to an API client's GET request, but I'm getting an error:
Body was inferred but the method does not allow inferred body parameters
Here's what I've got:
Dim sPath As String = &...
2
votes
1
answer
2k
views
Minimal API add complex parameters into swagger UI
After defining the endpoint
app.MapGet($"{baseRoute}/GetProducts", GetProductsAsync)
.WithName("GetProducts")
.Produces<ProductResponseDto>()
.WithTags(Tag);
With this async ...
0
votes
1
answer
659
views
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 ...
0
votes
0
answers
184
views
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 ...
0
votes
1
answer
2k
views
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 (...
-1
votes
1
answer
951
views
Why C# fire and forget is not working with http call in an API?
I have two minimal APIs, the receiver one is simple
var app = builder.Build();
app.MapGet("/testing", () =>
{
Console.WriteLine("Received");
});
app.Run();
The calling API ...
0
votes
1
answer
169
views
Is there a way to configure the serialization response in a minimal C# API?
I tried using the following line
builder.Services.Configure<JsonSerializerOptions>(options => options.Converters.Add(new JsonStringEnumConverter()));
to configure that the enums are ...
3
votes
2
answers
2k
views
Remove all default logging from Minimal Web API C# .NET
Is it possible to remove all logging from the minimal web api? I searched for it and my code currently looks like this:
builder.Services.AddLogging(b => {
b.ClearProviders();
});
This almost ...
2
votes
1
answer
4k
views
FluentValidation validate automatically the request .NET 7 Minimal API
I'm using FluentValidation 11.5.1.
I don't want to use:
// MapPost //
public static void AddUser([FromBody] UserRequest, [FromServices] IValidator<UserRequest> validator)
I want it to be ...
0
votes
0
answers
71
views
Is it possible to use Newtonsoft JSON in minimal API instead of System.Text.Json? [duplicate]
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 also...
builder....
1
vote
2
answers
134
views
Why does Results.Json special-case null (and can I get it to stop doing that)?
Consider the following minimal repro example using the default ASP.NET Core template:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Content-Type application/json, ...
2
votes
1
answer
996
views
Separate Program.cs to Startup.cs in ASP.NET WebAPI Minimal for Integration testing
I am trying to write integration tests for my web service.
I want to separate Program.cs into Startup.cs so test class can mock TestStartup.cs(or something like so). The point is swapping real ...
3
votes
2
answers
2k
views
Why `ardalis/CleanArchitecture` reference FastEndpoints but not it's own `ardalis/ApiEndpoints`
Just need a clarification.
I was keen on referencing ApiEndpoints in one of my projects.
But when I am browsing the ardalis/CleanArchitecture repo I noted it has been using FastEndpoints ref.
The ...
3
votes
1
answer
2k
views
Getting the request body as a string in and EndpointFilter .Net 7
I created a simple endpoint filter on a C# minimal api and when I try to get the body into a string it is always blank.
app.MapPost("/todo", async (Todo todo) =>
{
await Task.Run(() =&...
1
vote
2
answers
3k
views
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 ...
0
votes
1
answer
1k
views
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 ...
2
votes
2
answers
4k
views
Minimal API Results.Ok Not Returning Full Object
While working on a larger Minimal API project, Results.Ok() was not returning the full object. However, switching to Results.Text() returns the full object.
I've included the full listing of a simple ...
1
vote
2
answers
996
views
How to get rid of code duplication for Minimal API's
I am trying to learn to effectively use Minimal API's. How can I reduce duplicate codes, how to create base Endpoint class and do the most job there?
Especially, how to use Mediatr from a static ...
1
vote
1
answer
519
views
Error Deploying Asp.Net Minimal API (Top level statements) to lambda using CDK
I have a CDK solution with a stack etc and in the same solution i have created a ASP.NET minimal API Lambda project.
When I deploy using the CDK I'm getting the ERROR:
Internal Server Error
When I ...
3
votes
1
answer
1k
views
.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 ...
3
votes
1
answer
2k
views
How to provide OpenAPI 'tag' group descriptions for a .NET Core 7 minimal API?
I've grouped my API endpoints into two tag/groups: "MCP Provider" and "Nexgen Provider". How can I apply a description to the tags themselves?
-2
votes
1
answer
150
views
Is it possible to connect a backend MVC C# API with a separate frontend React project?
I am trying to create a conceptual diagram after researching for a while, it seems like you need to use minimal API if you want to mesh it with a React frontend. Is it possible to do this with the MVC ...
2
votes
0
answers
842
views
What proper technique for MAUI to use API for Login
I have a Blazor Server web application that uses Identity(DbContext, ApplicationUser) to login and register users.
I am creating a .Net Core 7.0 Web API to handle the login and database interactions ...
2
votes
1
answer
285
views
MinimalAp IEndpointFilter MapGet Get Pattern
In the IEndpointFilter would like to get the route used.
app.MapGet("/get/{productId:guid}", ......
public class MyFilter : IEndpointFilter
{
public async ValueTask<object?> ...
1
vote
2
answers
5k
views
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)
...
0
votes
1
answer
407
views
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 ...
2
votes
1
answer
210
views
Resolving a DI error with Mediatr and .NET Core 7 Minimal APIs
I am currently getting a DI related error message when I try to run my minimal API app with the following classes. Any help would be greatly appreciated.
Endpoint
public static void DefineEndpoints(...
1
vote
0
answers
122
views
When I host 2 apps (Web API and Blazor server) on Windows Server 2019, the API localhost port refuses to connect to SQL Server database on IIS
When I publish both projects to a local Windows IIS, they both run smoothly, but when I publish to Windows Server 2019, I get an error
No connection could be made because the target machine actively ...
0
votes
1
answer
2k
views
.net 7 Route Handling and Parameter Binding in minimal apis [duplicate]
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 ...
3
votes
1
answer
1k
views
My minimal ASP.NET Core Web API returns error 405: Method not allowed
I want to update a record by calling my api endpoint using the put verb but his returns error 405 method not allowed.
My api endpoint:
app.MapPut("/sirs/{Id}", async (int Id, SIRCContext db, ...
0
votes
1
answer
385
views
Disabling CORS in Minimal API Ocelot Gateway
So the problem is that i have Blazor WebAssembly for a front-end, Making API calls through the Ocelot API Gateway but for some reason the CORS are failing
but in Ocelot Gateway in Program.cs i have
...
0
votes
1
answer
418
views
How to handle MultipartBodyLengthLimit in Minimal APIs with custom model binding from Form
My code is working, but I'm looking to see if I'm doing this in the 'proper' fashion. I have a Minimal API that supports file uploads but also I needed to pass required meta data along with the files,...
0
votes
1
answer
440
views
How to use automapper in minimal api?
I am trying to use automapper in my new minimal api's project that i connected with cosmos db. When i try to get all of my objects i get the error: "Missing type map configuration or unsupported ...
1
vote
1
answer
1k
views
Post request to Minimal API service with JSON body
I've got a minimal API service with a MapPost:
app.MapPost("/sendmessage", (RabbitMessage rm) => server.SendMessage(rm.exchange,
rm.routingkey, rm.message));
app.Run();
record ...
0
votes
1
answer
980
views
.NET 7.0 Change the webrootpath at runtime based on the Request.Host - How to get the host in webapplication builder
I have wwwroot folder organized for each subdomain as below. The application is based on .NET 7.0 and want to Use StaticFiles from different folders in webroot
wwwroot
-- folder1.abc.com
--...
2
votes
1
answer
1k
views
HEAD Verb in Minimal API C#
HEAD
The HTTP HEAD method requests the headers that would be returned if the HEAD
request's URL was instead requested with the HTTP GET method.
For example, if a URL might produce a large download,a ...
1
vote
1
answer
1k
views
How does .NET Core C# Minimal API fill parameters?
With minimalistic API how does MapGet automatically fill parameters from querystring?
With minimalistic API the following is possible:
var builder = WebApplication.CreateBuilder(args);
var app = ...
0
votes
1
answer
60
views
How to Send Request from MInimaApi instance to another MVC instance
I'm trying to create API working by minimalApi service who can be accessible from public and can send GET/POST/PUT request to my Web Service with Controllers.
But every time when I Send GET to my ...
1
vote
2
answers
961
views
c# how to pass stored procedure parameter into api dynamically
I'm creating web api using .net core7 minimal api.
I create a function to call stored procedure which get from table in database.
I'm facing a problem to pass the sp parameter into the function.
...
0
votes
2
answers
2k
views
.NET Core 7 minimal post body logging
I'm using .NET Core 7, Minimal API and I would like to log POST request body.
I use following code:
var endpoints = app.MapGroup("api/v1")
.AddEndpointFilter<...
0
votes
1
answer
76
views
I could use a app.UseWhenElse() method, but it does not exist. Is there an alternative?
This would be interesting:
app.UseWhenElse(
context => context.condition(),
applicationBuilder => { /* Condition is true */ },
applicationBuilder => { /* Condition is false */ }
...
2
votes
1
answer
4k
views
ASP.NET Core Minimal API not picking up request headers when hosted on VM
So I'm running a Linux VM (DigitalOcean Droplet) to host my ASP.NET Core Minimal API, I've got one endpoint that requires a refresh token to be supplied in the header and have done so using the ...
3
votes
1
answer
2k
views
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 ...
0
votes
1
answer
394
views
Can I make the browser play an MP3 instead of downloading it?
This is a bit tricky. I have a Minimal Web API with this function:
app
.MapGet("/Speak/{name}/{*text}", (HttpContext context, string name, string text) =>
{
string mp3Name ...
1
vote
1
answer
381
views
Is it possible to use app.UseWhen() to only have endpoints with specific conditions?
I have this code:
app.UseWhen(context => context.User.Identity?.IsAuthenticated ?? false, applicationBuilder =>
{
app
.MapGet("/User", (HttpContext context) => Json(...
0
votes
1
answer
424
views
I'm getting a transient failure with MySQL and MariaDB
I am working on a simple Web API that uses MySQL as database. It's pretty basic:
var builder = WebApplication.CreateBuilder(args);
builder
.Services
.AddDbContext<RequestContext>(options ...