From the course: Building Web APIs with ASP.NET Core 8

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Making the API asynchronous

Making the API asynchronous

- [Instructor] And finally, since we are working with the data store so much, we may want to make our actions asynchronous. That's a rather easy task thanks to what .NET offers us. All we need to do is change the method signature. So instead of public IEnumerable of product, we can do public async task of IEnumerable of product, and then we have to call await within that method whenever we have another asynchronous call. So for instance, if we call ToList on the products that we receive via Entity Framework Core, we could do this asynchronously because then when we call ToList, the data from data store is materialized so we can access it. Entity Framework Core tries to do that as late as possible because anything we change in our query could change the sequel that is then sent to the data store. And therefore this materialization phase is always important and can also take a tiny bit of time, and therefore an asynchronous call might be a good idea. Also, when working with…

Contents