Closed JKamsker closed 5 months ago
just tried the following and it works as expected.
sealed class GetEndpoint : EndpointWithoutRequest
{
public override void Configure()
{
Get("something/{id}");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken c)
{
await SendAsync(Route<int>("id"));
}
}
sealed class CreateEndpoint : EndpointWithoutRequest
{
public override void Configure()
{
Post("create");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken c)
{
await SendCreatedAtAsync<GetEndpoint>(new { id = 100 }, "created!", generateAbsoluteUrl: true);
}
}
does not properly redirect to the intended endpoint
fyi, the only responsibility of the endpoint is to correctly add a location
header to the response. it does not automatically redirect the web browser. typically, your client app will read the location header for 201 responses and do the redirection itself.
also, if you're customizing endpoint names via the .WithName()
extension method, you need to use the given custom names as explained here in the pink note section.
if i'm off base, pls attach a repro project i can debug and understand what exactly you're trying to do.
Oh thats why, thanks! All of my endpoints have a custom name to be easier readable in swagger/redoc. Would it be hard to make fastendpoints aware of my custom names automatically?
we've tried to come up with a solution for that, but have not succeeded yet.
Description
The
SendCreatedAt
method in the FastEndpoints library does not properly redirect to the intended endpoint. The issue arises because thetypeof(TEndpoint).EndpointName(verb?.ToString("F"), routeNumber)
does not resolve to the correct endpoint name. For instance, in my case, it incorrectly resolves toMyAppApplicationFeaturesTestsEntitiesGetTestEntityEndpoint
but should rather be something likeGet TestEntity
Steps to Reproduce
SendCreatedAt
method in a FastEndpoints endpoint.Code References
The problematic code is located in https://github.com/FastEndpoints/FastEndpoints/blob/56105b3daee748f5b8f468f10bfbf97e425a7101/Src/Library/Extensions/HttpResponseExtensions.cs#L72-L88
The
linkGen.GetPathByName(endpointName, routeValues);
method is called in https://github.com/FastEndpoints/FastEndpoints/blob/56105b3daee748f5b8f468f10bfbf97e425a7101/Src/Library/Extensions/HttpResponseExtensions.cs#L102-L125Problem
The
linkGen
object attempts to look up the endpoint name in its dictionary and returnsnull
because the dictionary entries only contain items like[Get TestEntity, Microsoft.AspNetCore.Http.Endpoint[]]
. However, the lookup is performed using the incorrectly resolved endpoint nameMyAppApplicationFeaturesTestsEntitiesGetTestEntityEndpoint
.Expected Behavior
The
SendCreatedAt
method should correctly resolve the endpoint name to match the entries in theEndpointNameAddressScheme
dictionary and perform the redirection to the intended endpoint.Additional Information
EndpointNameAddressScheme
dictionary.