[Fast-Endpoints] Awesome Library to minimize APIs even more.

Author:

FastEndpoints is a library that follows the pattern of minimal APIs. If want to make a web API project even minimal, this lib is the reference you could archive.

It does separate the concern of SOLID (Single Responsibility one) towards the organization of endpoints

On FastEndpoints each endpoints should be on a different file

The sample project

This is the solution tree, you can noticed the separations of Endpoints, Entities, Requests, Responses and Services.

A initial configuration is need so you be able to run the project.

Endpoints structure

The image below shows how’s the implementation of this library in order to create an endpoint.

If a endpoint has a request and a response, it should inherit from Endpoint<TRequest, TResponse> class.

You should override two methods: Configure() and the Respective HandleAsync()

On the HandleAsync, when you need to send the response you should call SendAsync(), the parameter of this function will be the TResponse object.

Testing it

How Dependency Injection Works?

Following the documentations there are tree ways to do it.

  • By property declaration
    • public IPersonRepository _personRepository { get; set; }
  • By traditional constructor declaration

More endpoints samples.

Note that this specific screenshot below doesn’t inherit from Endpoint but from EndpointWithoutRequest<TRespone> that means you’re not expecting a request object.

In order to get the value from route (query string)

  • Getting by Id (query string parameter)

Deleting endpoint

Notice the part in red, this Delete() indicates the expected HTTP method.

And the second await SendNoContentAsync(); is telling the request that we are going to send 204 – NoContent as response.

  • The endpoint in action

Conclusion

This is really awesome tool if you want to create WEB APIs with a clearly separation of responsibilities. The project the uses this library is expected to developers to see a easy understand of the business.

I would go for this tool if I get the change to build a WEB API project from the scracth.

The complete code you find here -> https://github.com/rpbs/FastEndpointsAwesomeLibrary

Source: Get Started | FastEndpoints

Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *