For a great primer on Minimal APIs, check out Shawn Wildermuth's article entitled “ Minimal APIs in. You then have the rest of your app.Map*() methods that retrieve a single product, post a new product, update an existing product and delete a product, as shown in Listing 1. In this example, I'm using hard-coded Product objects, whereas in a real application, you'd most likely use the Entity Framework to retrieve these from a database table. In the Program.cs file, you write an app.MapGet() method to return a set of Product objects. You normally have a Product class with basic properties such as ProductID, Name, Color, and ListPrice, as shown in the following code snippet. Let's look at a simple Minimal Web API system that works with product data. In this article, you're going to see how to move each group of Web APIs into their own router class to provide a much more consistent and maintainable way to create Minimal Web API calls. For example, if you have a set of CRUD routes for working with products and another set for working with customers, create a ProductRouter class and a CustomerRouter class. Instead of keeping all your app.Map*() methods in the Program.cs file, you should create a router class to separate your groups of app.Map() methods into. NET 6, but as the number of routes grows, your Program.cs file can easily become overwhelming to maintain. It's very easy to get started using Minimal Web APIs in.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |