Reader small image

You're reading from  Web API Development with ASP.NET Core 8

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781804610954
Edition1st Edition
Concepts
Right arrow
Author (1)
Xiaodi Yan
Xiaodi Yan
author image
Xiaodi Yan

Xiaodi Yan is a seasoned software engineer with a proven track record in the IT industry. Since 2015, he has been awarded Microsoft MVP, showcasing his dedication to and expertise in .NET, AI, DevOps, and cloud computing. He is also a Microsoft Certified Trainer (MCT), Azure Solutions Architect Expert, and LinkedIn Learning instructor. Xiaodi often presents at conferences and user groups, leveraging his extensive experience to engage and inspire audiences. Based in Wellington, New Zealand, he spearheads the Wellington .NET User Group, fostering a vibrant community of like-minded professionals. Connect with Xiaodi on LinkedIn to stay updated on his latest insights.
Read more about Xiaodi Yan

Right arrow

Preface

Welcome to the world of ASP.NET Core!

.NET Core has undergone significant evolution since its inception and has emerged as a robust solution for building a wide array of applications, including web, desktop, mobile, gaming, and AI applications. With the release of .NET 8 at the end of 2023, it solidified its position as one of the most powerful and versatile frameworks for modern applications.

ASP.NET Core, built on top of the .NET Core platform, inherits its strengths, offering cross-platform compatibility, exceptional performance, and a modular architecture. It has become a popular choice for building cloud-native applications that can run seamlessly on any operating system, including Windows, macOS, and Linux, and can be deployed on any cloud platform, such as Azure, AWS, or GCP.

As organizations increasingly adopt ASP.NET Core for web application development, the demand for ASP.NET Core developers is on the rise. Whether you’re transitioning from the traditional .NET Framework or are new to web API development with ASP.NET Core, this book is tailored to meet your needs. It will guide you through building your first web API application with ASP.NET Core and provide you with the knowledge and skills to build robust, scalable, and maintainable web APIs.

While ASP.NET Core offers robust options for frontend development, such as Razor Pages, Blazor, and MVC, this book focuses on backend development. You’ll explore a range of topics, including REST-based APIs, gRPC APIs, GraphQL APIs, and real-time APIs, gaining insights into essential concepts and best practices for building web APIs with ASP.NET Core.

Additionally, we’ll delve into testing methodologies and tools such as unit testing and integration testing to ensure the quality and reliability of your web APIs. We’ll also explore modern development practices such as CI/CD, containerization, monitoring, and cloud-native design patterns, essential for contemporary web API development.

While this book serves as a foundational resource, it merely scratches the surface of what ASP.NET Core has to offer. I encourage you to use it as a stepping stone to further explore the vast landscape of ASP.NET Core on your own. Experiment with the sample code provided and refer to the links in the book for more in-depth learning. Don’t forget to explore the official documentation for the latest updates and features.

I hope you will find this book useful and it will inspire you to explore the world of ASP.NET Core. Happy reading!

Who this book is for

This book is for developers who want to learn how to build web APIs with ASP.NET Core 8 and create flexible, maintainable, scalable applications with the .NET platform. Prior basic knowledge of C#, .NET, and Git would be helpful.

What this book covers

Chapter 1, Fundamentals of Web APIs, provides an overview of web APIs, covering their historical background and various API styles, including REST-based APIs, gRPC APIs, GraphQL APIs, and real-time APIs. It will also discuss the process of designing web APIs.

Chapter 2, Getting Started with ASP.NET Core Web APIs, explores the fundamentals of ASP.NET Core, including the project setup, dependency injection, and minimal APIs. You will also learn how to create your first web API using ASP.NET Core and how to test it using a variety of tools.

Chapter 3, ASP.NET Core Fundamentals (Part 1), covers the fundamentals of ASP.NET Core, including routing, configuration, and environments.

Chapter 4, ASP.NET Core Fundamentals (Part 2), continues the discussion of ASP.NET Core fundamentals, covering logging and middleware.

Chapter 5, Data Access in ASP.NET Core (Part 1: Entity Framework Core Fundamentals), explores the utilization of Entity Framework Core (EF Core) for database interaction. You will gain insights into implementing CRUD operations using EF Core.

Chapter 6, Data Access in ASP.NET Core (Part 2: Entity Relationships), covers the configuration of EF Core to support various model relationships, including one-to-one, one-to-many, and many-to-many.

Chapter 7, Data Access in ASP.NET Core (Part 3: Tips), provides best practices for using EF Core in your web API, such as the DbContext pooling, raw SQL queries, bulk operations, and so on.

Chapter 8, Security and Identity in ASP.NET Core, covers the security considerations surrounding web APIs. You will delve into implementing authentication and authorization mechanisms using ASP.NET Core Identity to ensure the security of your web APIs.

Chapter 9, Testing in ASP.NET Core (Part 1 – Unit Testing), explores testing methodologies and tools, including xUnit and Moq. You will learn how to implement unit tests to ensure the quality of your web APIs.

Chapter 10, Testing in ASP.NET Core (Part 2 – Integration Testing), covers integration testing using xUnit and WebApplicationFactory. You will learn how to implement integration tests to test components of your web APIs.

Chapter 11, Getting Started with gRPC, explores gRPC, a modern high-performance RPC framework that can be used to build efficient APIs. You will learn how to create gRPC services and clients using ASP.NET Core.

Chapter 12, Getting Started with GraphQL, covers GraphQL, a powerful query language for APIs. You will learn how to create GraphQL APIs using ASP.NET Core.

Chapter 13, Getting Started with SignalR, explores SignalR, a real-time communication framework for ASP.NET Core. You will learn how to create real-time APIs and clients using ASP.NET Core.

Chapter 14, CI/CD for ASP.NET Core Using Azure Pipelines and GitHub Actions, covers the process of building, testing, and deploying your web API applications using Azure DevOps and GitHub Actions. It also introduces the use of Docker to containerize your web API applications.

Chapter 15, ASP.NET Core Web API Common Practices, provides best practices for building your ASP.NET Core web API applications. It covers topics such as asynchronous programming, caching, HttpClientFactory, and so on.

Chapter 16, Error Handling, Monitoring, and Observability, covers error handling, health checks, monitoring, and observability. You will learn how to handle errors in your web APIs and how to monitor and observe your web APIs using a variety of platforms and OpenTelemetry.

Chapter 17, Cloud-Native Patterns, explores advanced architecture and patterns essential for modern web API development. You will gain insights into cloud-native design patterns, Domain-Driven-Design (DDD), Command Query Responsibility Segregation (CQRS), Retry patterns, Circuit Breaker patterns, and so on.

Chapter 18, Leveraging Open-Source Frameworks, covers various open-source frameworks that can be used to streamline development and enhance productivity, including ABP Framework, Clean Architecture, Orchard Core, eShop, and .NET Aspire.

To get the most out of this book

You will need to have a basic understanding of programming using .NET and C# and be familiar with the concepts of object-oriented programming (OOP). If you are new to C#, you can learn C# from Microsoft Learn and freeCodeCamp at https://www.freecodecamp.org/learn/foundational-c-sharp-with-microsoft.

Software/hardware covered in the book

Operating system requirements

.NET 8 SDK (https://dotnet.microsoft.com/en-us/download/dotnet)

Windows, macOS, or Linux

Visual Studio Code (https://code.visualstudio.com/)

Windows, macOS, or Linux

Visual Studio 2022 Community Edition (https://visualstudio.microsoft.com/downloads/)

Windows, macOS, or Linux

Seq (https://datalust.co/download)

Windows, Docker/Linux

Prometheus (https://prometheus.io/download/)

Windows, Docker/Linux

Grafana (https://grafana.com/oss/grafana/)

Windows, Docker/Linux

Jaeger (https://www.jaegertracing.io/download/)

Windows, Docker/Linux

Azure

Azure DevOps

GitHub

In this book, we use LocalDB, which is a lightweight version of SQL Server. It is only available on Windows. If you are using a Mac or Linux, you can use a Docker container to run SQL Server. You can also use SQLite instead. To use SQLite, you need to update the connection string in the appsettings.json file and install the SQLite provider for EF Core, respectively. Please refer to Chapter 5 for more details.

We advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you learn better and retain the knowledge longer.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Web-API-Development-with-ASP.NET-Core-8. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Let us use the IEnumerable interface to query the database.”

A block of code is set as follows:

using (var serviceScope = app.Services.CreateScope()){    var services = serviceScope.ServiceProvider;    // Ensure the database is created.    var dbContext = services.GetRequiredService<AppDbContext>();    dbContext.Database.EnsureCreated();}

Any command-line input or output is written as follows:

cd GrpcDemo.Client dotnet add GrpcDemo.Client.csproj package Grpc.Net.Client

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Click the Continue button.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Web API Development with ASP.NET Core 8, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere? Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application. 

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781804610954

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Web API Development with ASP.NET Core 8
Published in: Apr 2024Publisher: PacktISBN-13: 9781804610954
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Xiaodi Yan

Xiaodi Yan is a seasoned software engineer with a proven track record in the IT industry. Since 2015, he has been awarded Microsoft MVP, showcasing his dedication to and expertise in .NET, AI, DevOps, and cloud computing. He is also a Microsoft Certified Trainer (MCT), Azure Solutions Architect Expert, and LinkedIn Learning instructor. Xiaodi often presents at conferences and user groups, leveraging his extensive experience to engage and inspire audiences. Based in Wellington, New Zealand, he spearheads the Wellington .NET User Group, fostering a vibrant community of like-minded professionals. Connect with Xiaodi on LinkedIn to stay updated on his latest insights.
Read more about Xiaodi Yan