How to use route handler filters in nominal APIs in ASP.Net Main 7


ASP.Internet Main 6 released a simplified web hosting model that makes it possible for us to establish light-weight APIs with minimum dependencies. Negligible APIs in ASP.Internet Core 6 don’t use controllers, and they deficiency assist for a variety of helpful ASP.Internet characteristics. Just one of these missing capabilities is filters.

Nevertheless, with ASP.Internet Core 7 (now available in a launch applicant), we can acquire advantage of the freshly released IRouteHandlerFilter interface to incoporate filters in our negligible APIs. These filters can be utilised to modify the request or response objects as sought after or to limited-circuit the ask for processing pipeline.

This article discusses how we can get the job done with route handler filters when creating minimal API applications in ASP.Web Main 7. To use the code examples furnished in this post, you really should have Visible Studio 2022 Preview set up in your method. If you really do not presently have a copy, you can obtain Visual Studio 2022 here.

Create an ASP.Internet Core 7 minimum Web API undertaking in Visible Studio 2022

First off, let’s create an ASP.Web Core 7 challenge in Visual Studio 2022 Preview. Adhere to these techniques:

  1. Launch the Visual Studio 2022 Preview IDE.
  2. Click on on “Create new project.”
  3. In the “Create new project” window, decide on “ASP.Net Main World-wide-web API” from the list of templates shown.
  4. Click Future.
  5. In the “Configure your new project” window, specify the title and spot for the new undertaking.
  6. Optionally check the “Place option and challenge in the very same directory” examine box, based on your tastes.
  7. Click on Next.
  8. In the “Additional Information” window demonstrated future, uncheck the check out box that says “Use controllers…” due to the fact we’ll be working with negligible APIs in this case in point. Go away the “Authentication Type” as “None” (default).
  9. Ensure that the look at bins “Enable Docker,” “Configure for HTTPS,” and “Enable Open API Support” are unchecked as we won’t be utilizing any of these characteristics right here.
  10. Simply click Build.

We’ll use this ASP.Web Core 7 World-wide-web API project to build a minimal API and put into practice route handler filters in the sections beneath.

What are filters? Why must we use them?

Filters permit you to operate code at specified stages of the ask for processing pipeline. In other text, a filter is a piece of code that is executed ahead of or just after an motion process is executed. For case in point, you could use a filter to log each time anyone accesses a internet webpage or to validate the ask for parameters despatched to an endpoint.

Copyright © 2022 IDG Communications, Inc.


Resource : https://www.infoworld.com/article/3674589/how-to-use-route-handler-filters-in-nominal-apis-in-aspnet-main-7.html#tk.rss_all

Leave a Comment

SMM Panel PDF Kitap indir