Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Minimal APIs in ASP.NET 9

You're reading from   Minimal APIs in ASP.NET 9 Design, implement, and optimize robust APIs in C# with .NET 9

Arrow left icon
Product type Paperback
Published in Dec 2024
Publisher Packt
ISBN-13 9781805129127
Length 252 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nick Proud Nick Proud
Author Profile Icon Nick Proud
Nick Proud
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1 - Introduction to Minimal APIs FREE CHAPTER
2. Chapter 1: Getting Up and Running with Minimal API Development 3. Chapter 2: Creating Your First Minimal API 4. Chapter 3: The Anatomy of a Minimal API 5. Part 2 - Data and Execution Flow
6. Chapter 4: Handling HTTP Methods and Routing 7. Chapter 5: The Middleware Pipeline 8. Chapter 6: Parameter Binding 9. Chapter 7: Dependency Injection in Minimal APIs 10. Chapter 8: Integrating Minimal APIs with Data Sources 11. Chapter 9: Object Relational Mapping with Entity Framework Core and Dapper 12. Part 3 - Optimal Minimal APIs
13. Chapter 10: Profiling and Identifying Bottlenecks 14. Chapter 11: Utilizing Asynchronous Programming for Scalability 15. Chapter 12: Caching Strategies for Enhanced Performance 16. Part 4 - Best Practices, Design, and Deployment
17. Chapter 13: Best Practices for Minimal API Resiliency 18. Chapter 14: Unit Testing, Compatibility, and Deployment of Minimal APIs 19. Index 20. Other Books You May Enjoy

Request validation and error handling

There are several different methods of validation at our disposal. We’re going to look at two of them in this section: manual validation and data annotation and model binding validation.

Manual validation

This kind of validation is the simplest, as you are writing code inside the route handler (the body of the lambda expression within an endpoint) that validates the request and decides on the appropriate response.

We’ve already applied manual validation in some parts of the todo items API. For example, the PATCH method we created to update the due date on items first checks for the Todo item with the target ID. It could just assume that TodoItem exists in the list, but instead, we check first to see if it exists and then return a 404 NOT FOUND status code if this is the case:

app.MapPatch("/updateTodoItemDueDate/{id}",
    (int id, DateTime newDueDate) =>
{
    var index...
lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Minimal APIs in ASP.NET 9
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon