Building an Async API with ASP.NET Core

Coding an asynchronous API comes with its own set of challenges. In this course you'll learn what they are and how you can benefit from writing async code. You'll learn how to do that starting at the bottom layer and working right up to the top.
Course info
Rating
(89)
Level
Intermediate
Updated
Aug 14, 2018
Duration
2h 42m
Table of contents
Course Overview
Understanding the Power of Async
Starting at the Bottom with Your Data Access Layer
Asynchronously Reading Resources
Asynchronously Manipulating Resources
Understanding How to Integrate with External Services Using Async
Avoiding Common Pitfalls
Description
Course info
Rating
(89)
Level
Intermediate
Updated
Aug 14, 2018
Duration
2h 42m
Description

Coding an asynchronous API comes with its own set of challenges. In this course, Building an Async API with ASP.NET Core, you will gain the ability to increase the scalability and performance of your API by writing async code. First, you will learn how asynchronous code actually works and what the advantages can be. Next, you will discover how to consume an EF Core data store asynchronously, how to expose that data via an API, and how to call into a service asynchronously. Finally, you will explore how to avoid common pitfalls when writing async code. When you’re finished with this course, you will have the skills and knowledge of asynchronous code needed to build a fully async API with ASP.NET Core.

About the author
About the author

Kevin Dockx is a freelance solution architect (mobile/web), author & consultant, living in Antwerp (Belgium).

More from the author
Using HttpClient to Consume APIs in .NET Core
Intermediate
3h 20m
Jan 11, 2019
More courses by Kevin Dockx
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hello, my name is Kevin. Welcome to my course Building an Async API with ASP. NET Core. Coding an asynchronous API comes with its own set of challenges. In this course, you will gain the ability to increase the scalability and performance of your API by writing async code. First, you will learn how asynchronous code actually works and what the advantages can be. Next, you will discover how to consume an Entity Framework Core data stored asynchronously, how to expose that data via an API, and how to call into a service asynchronously. Finally, you will explore how to avoid common pitfalls when writing async code. When you're finished with this course, you will have the skills and knowledge of asynchronous code needed to build a fully async API with ASP. NET Core. I hope you'll join me and I look forward to helping you on your learning journey here at Pluralsight.

Understanding the Power of Async
Hi there and welcome to the Building an Async API with ASP. NET Core course at Pluralsight. I'm Kevin and I'll guide you through it. In this module, we'll first of all cover the prerequisites and tooling required for this course. We'll learn where and how async code can offer advantages when building APIs, and for that, we'll look into how synchronous and asynchronous requests are handled. We'll also look into I/O versus computational bound work and we'll cover some terminology, like multithreading, concurrency, and parallelism. If you happen to have any questions, the best place to pose them is on the Discussions tab on the course page. I check this regularly, and like that the questions and answer can help other people as well. For very short questions that require a quick answer, you can contact me on Twitter, or just follow me if you want to know about my upcoming courses, user group events, or are interested in the technology I'm interested in. I mainly tweet regarding ASP. NET Core, security, and APIs these days. Oh, and you might see the occasional picture of our family cat. Let's have a look at the course prerequisites and tooling.

Starting at the Bottom with Your Data Access Layer
When creating an async API, working bottom up is the way to go. In this module, we'll start with building our data access layer and a repository. I'm Kevin and I'll guide you through it. After all that theory from the previous module, let's have a look at how to achieve async in practice. In this module, we'll learn about async and await keywords used to support async in ASP. NET Core. We'll learn about tasks, the allowed return types for async methods, and what their, well, task or purpose is. And then we'll dive into code. We'll start from scratch and create a data access with Entity Framework Core. We'll then create an async repository that consumes the EF Core context, and along the way, we'll learn about naming guidelines, conventions, and best practices. Let's dive in.

Asynchronously Reading Resources
With our data access layer and repository in place, we can now start building the outer facing layer, or service layer. Let's have a look. We'll start by adding a controller with an action that calls into our repository asynchronously. We'll also learn how to test the effects on scalability async offers us. And lastly, we'll have a look at the AsyncResultFilter class. Let's dive in with a demo.

Asynchronously Manipulating Resources
When manipulating API resources that are eventually persisted to a database, via Entity Framework Core, it's important to know just when it makes sense to go async and when it doesn't. In this module, we'll learn all about it. I'm Kevin and I'll guide you through it. We'll start by creating one resource asynchronously, and then we'll learn how we can support bulk inserts. Let's dive in.

Understanding How to Integrate with External Services Using Async
It's quite common for a web API to call into another web API, if only for a matter of reusing what you've already got. That's a network call, which makes it a good use for async. In this module, you'll learn how to do that. I'm Kevin and I'll guide you through it. We'll start by learning how to call an external service or API asynchronously. But that's just the beginning. We'll also learn how to make different API calls and wait for those tasks to complete before continuing. When working with a set of calls and one of them fails, it makes sense to cancel the rest of the calls, because otherwise they're holding onto threads until they complete. And lastly, we'll learn how to gracefully handle exceptions. Let's dive in.

Avoiding Common Pitfalls
When integrating with legacy libraries that weren't built with async in mind, it's tempting to offload running that code to the background. That's a bad idea. In this module, we'll learn why and we'll also cover a few other potential pitfalls. I'm Kevin and I'll guide you through it. So in this module, we'll cover a few common pitfalls. We'll start by learning why we shouldn't asynchronously wrap synchronous legacy code, and then we'll learn how to ensure we don't hurt scalability by accidentally blocking our async code. Lastly, we'll learn why modifying shared state isn't thread safe. So in all the demos in this module, we'll write code we really shouldn't write and we'll learn why. Let's dive in.