FastEndpoints / FastEndpoints

A light-weight REST API development framework for ASP.NET 6 and newer.
https://fast-endpoints.com
MIT License
4.64k stars 277 forks source link

Query Parameters with Post #643

Closed ForteUnited closed 7 months ago

ForteUnited commented 7 months ago

Hello,

I have a very simple starter api using FastEndpoints for this issue.

I want to do a Post and use query parameters to bind to the DTO. I keep getting 415 Unsupported Media Type no matter what.

If I change it to GET, everything works just fine.

What am I doing wrong?

Here is the code:

using FastEndpoints;
using Microsoft.AspNetCore.Http.HttpResults;

namespace PrintService.WebApi2.Endpoints.Epson;

public class PrintRequest
{
    [QueryParam] 
    public string connectionType { get; set; } = string.Empty;
}

public class GetPrintRequest : Endpoint<PrintRequest, string>
{
    public override void Configure()
    {
        Post("/api/printrequest");
        AllowAnonymous(); //no security for now
    }

    public override async Task HandleAsync(PrintRequest req, CancellationToken ct)
    {
        await SendAsync(req.connectionType, 200, ct);
    }
}

Again, if I change this to GET, it works just fine.

dj-nitehawk commented 7 months ago

pls see here: https://github.com/FastEndpoints/FastEndpoints/issues/512#issuecomment-1780419593