As the title of this question tells, how could I do a GET request with Fast Endpoints in ASP.NET
Now I have tried to do this:
using api.Blogs.Shared;
using api.Data;
using AutoMapper;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace api.Blogs.ListBlogsEndpoint;
public class ListBlogsEndpoint(BlogDbContext context, AutoMapper.IMapper mapper) : Endpoint<ListBlogsRequest, BlogResponse[]>
{
public override void Configure()
{
Get("blogs");
}
public override async Task HandleAsync(ListBlogsRequest req, CancellationToken ct)
{
var blogs = await context.Blogs.ToArrayAsync(ct);
var response = blogs.Select(b => mapper.Map<BlogResponse>(b)).ToArray();
await SendOkAsync(response, ct);
}
}
But when I try to do a get request I get the following error:
TypeError: Failed to execute ‘fetch’ on ‘Window’: Request with GET/HEAD method cannot have body.
I don’t know what to do now, I have searched about it, and it seems that the Request in a GET request should be query parameters, but they are used here as a body