This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3100|Reply: 0

[Interface] ASP.NET Core (26) Interface (Minimal APIs) Minimal APIs

[Copy link]
Posted on 11/6/2023 9:13:52 PM | | | |
Requirements: .NET 6 has a new minimum API, build a minimum API to create HTTP APIs with minimal dependencies. They are ideal for microservices and applications that need to include minimal files, features, and dependencies in ASP.NET Core.

Based on personal experience, the following advantages may be present:

  • Reduced a lot of service dependencies;
  • Not as heavy as an MVC routing engine;
  • Suitable for deployment in small machines, such as embedded hardware;
  • It is more convenient to write a demo example, a .cs file can be done;


The following explicit attributes are supported:

  • Route value: [FromRoute]
  • Query string: [FromQuery]
  • Header: [FromHeader]
  • Text: [FromBody]
  • Form: [FromForm]
  • One service: [FromServices]
  • Parameter value: [AsParameters]


A minimum of 4 lines of code is required to start an HTTP service, the code is as follows:


Create a new GET interface with the following code:

As shown below:



The final call is the IEndpointRouteBuilder.Map method, which is as follows:


Reference:

The hyperlink login is visible.





Previous:Introduction to Nginx location configuration priority
Next:The difference between UEFI and traditional BIOS (Legacy).
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com