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
ASP.NET Core 9 Web API Cookbook

You're reading from   ASP.NET Core 9 Web API Cookbook Over 60 hands-on recipes for building and securing enterprise web APIs with REST, GraphQL, and more

Arrow left icon
Product type Paperback
Published in Apr 2025
Publisher Packt
ISBN-13 9781835880340
Length 344 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Luke Avedon Luke Avedon
Author Profile Icon Luke Avedon
Luke Avedon
Garry Cabrera Garry Cabrera
Author Profile Icon Garry Cabrera
Garry Cabrera
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Chapter 1: Practical Data Access in ASP.NET Core Web APIs FREE CHAPTER 2. Chapter 2: Mastering Resource Creation and Validation 3. Chapter 3: Securing Your Web API 4. Chapter 4: Creating Custom Middleware 5. Chapter 5: Creating Comprehensive Logging Solutions 6. Chapter 6: Real-Time Communication with SignalR 7. Chapter 7: Building Robust API Tests: a Guide to Unit and Integration Testing 8. Chapter 8: GraphQL: Designing Flexible and Efficient APIs 9. Chapter 9: Deploying and Managing Your WebAPI in the Cloud 10. Chapter 10: The Craft of Caching 11. Chapter 11: Beyond the Core 12. Index 13. Other Books You May Enjoy

Practical Data Access in ASP.NET Core Web APIs

ASP.NET Core 9 Web API Cookbook aims to be your comprehensive toolbox for building web APIs with ASP.NET Core 9—Microsoft’s latest version of ASP.NET Core. Our goal is to give you practical recipes you can use on the job. This cookbook provides step-by-step solutions to workaday problems such as implementing efficient data access patterns and secure authentication flows, to leveraging cutting-edge technologies such as .NET Aspire for cloud orchestration and distributed caching with HybridCache.

Throughout multiple chapters, we will cover the entire spectrum of RESTful APIs—from implementing robust testing strategies in Chapter 7 to working with .NET Aspire in Chapter 9 and tackling caching in Chapter 10. While RESTful APIs using JSON are the primary focus, the ASP.NET Core 9 web API offers additional powerful technologies for building APIs, such as GraphQL for efficient querying, gRPC for high-performance communication, and SignalR for real-time functionality. If you are transitioning from a legacy .NET Framework background, don’t miss the chapter on middleware. Middleware is perhaps the most significant architectural change from the module and handler system in .NET Framework.

In this chapter, we will explore best practices for retrieving data from an ASP.NET Core web API, including techniques for communicating from the data access layer to the consumer of the API. We will focus on paging and retrieving data with Entity Framework (EF) Core. We will also cover two of the three new LINQ methods, CountBy and AggregateBy, to return additional grouping information on your data.

The following recipes will be covered in this chapter:

  • Creating a mock database for EF Core with Bogus
  • Using ProblemDetails to return more robust error information
  • Creating a categories endpoint using the new LINQ CountBy
  • Implementing KeySet pagination
  • Configuring a CORS policy to expose pagination metadata
  • Implementing efficient first- and last-page access with EF Core
  • Testing the API in PowerShell
  • Using the new AggregateBy LINQ method to return the average price per category
You have been reading a chapter from
ASP.NET Core 9 Web API Cookbook
Published in: Apr 2025
Publisher: Packt
ISBN-13: 9781835880340
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 AU $24.99/month. Cancel anytime
Modal Close icon
Modal Close icon