So I'm writing a WEB API with .NET 5 and I started with something like this to get my data:
public ProfileModel Get(string email)
{
using (JobsDB data = new JobsDB())
{
return data.Profiles.Where(x => x.Email.ToUpper() == email.ToUpper()).FirstOrDefault();
}
}
But I just ran across an article that made me think I should be writing it using async/await like this:
public async Task<ProfileModel> Get(string email)
{
using (JobsDB data = new JobsDB())
{
return await data.Profiles.Where(x => x.Email.ToUpper() == email.ToUpper()).FirstOrDefaultAsync();
}
}
Now I realize that when the client application calls the WEB API, they will do so in an asynchronous manner (in their JavaScript code), so I always thought that the WEB API itself didn't have to use asynchronous methods. So is there a true advantage to using async/await in the WEB API itself? Is it considered "best practices" to do so anyway?