Making API Controllers Asynchronous
Learn to make API controller asynchronous.
We'll cover the following
In this section, we are going to make the unanswered questions endpoint asynchronous to make it more scalable.
At the moment, all of our API code has been synchronous. For synchronous API code, when a request is made to the API, a thread from the thread pool will handle the request. If the code makes an I/O call (such as a database call) synchronously, the thread will block until the I/O call has finished. The blocked thread can't be used for any other work—it simply does nothing and waits for the I/O task to finish. If other requests are made to our API while the other thread is blocked, different threads in the thread pool will be used for the other requests. The following diagram is a visualization of synchronous requests in ASP.NET:
Get hands-on with 1400+ tech skills courses.