ikyriak / IdempotentAPI

A .NET library that handles the HTTP write operations (POST and PATCH) that can affect only once for the given request data and idempotency-key by using an ASP.NET Core attribute (filter).
MIT License
283 stars 40 forks source link

Added MinimalAPI webapi project #45

Closed hartmark closed 1 year ago

hartmark commented 1 year ago

We have a minimal API and we wanted to use this nugget, but it seems MVC action filters isn't supported so we have used EndpointFilters that was added in .NET 7.

To make use of the endpoint filter you just need to add .AddEndpointFilter<IdempotentEndpointFilter>()

We cannot decorate the action with any attribute so we inject IdempotencyAttributeFilter, And IdempotentEndpointFilter uses this injected instance. So we will have same settings for all endpoints with this implementation.

We will continue use this implementation in our application and haven't tested every different combinations of calls yet, but the preliminary testing looks alright.

One way forward for this nuget would be to make an abstraction layer that the endpoint filtering in minimal API can interface with instead of do the magic hackery found in IdempotentEndpointFilter

Do anyone have any comments and/or suggestions for our implementation?

hartmark commented 1 year ago

I have identified some issues still to resolve when I wrote some more tests. I will leave the PR open until I have fixed the remaining issues.

Remaining issues:

hartmark commented 1 year ago

Alright, we have fixed the tests and fixed the implementation of IdempotentEndpointFilter.

This will be the solution we will be use in our application using minimal API.

ikyriak commented 1 year ago

@hartmark Thank you for your time and effort, and sorry for the delayed response 🙏

hartmark commented 1 year ago

@hartmark Thank you for your time and effort, and sorry for the delayed response 🙏

No worries, life happens sometimes 😀

Any feedback on the PR yet?

ikyriak commented 1 year ago

@hartmark Thank you for your effort and time 🙏 . The IdempotentAPI.MinimalAPI is introduced in Release 2.1.0. The Endpoint filter is renamed to IdempotentAPIEndpointFilter.

app.MapPost("/example",
    ([FromQuery] string yourParam) =>
    {
        return Results.Ok(new ResponseDTOs());
    })
    .AddEndpointFilter<IdempotentAPIEndpointFilter>();
hartmark commented 1 year ago

Nice! 🎉

Is the nugget updated with the latest code now?

ikyriak commented 1 year ago

@hartmark Yes, NuGet libraries v2.1.0 has the latest code.