Async Requests

In this lesson, we will learn how to handle async Requests for APIs.

What is an async request?

Synchronous request blocks the execution of server code until the response is received, whereas asynchronous request (async in short), does not block the execution and returns a callback to the client which can be used to receive the actual data once the execution is complete.

Handling async requests

REST Assured does not support async requests out of the box. We can automate these use cases using a third-party open-source library.

We will be using asynchttpclient for the same and to use this, let’s add below dependency to our build file.

Maven

Add this in the pom.xml file:

<dependency>
    <groupId>org.asynchttpclient</groupId>
    <artifactId>async-http-client</artifactId>
    <version>2.12.0</version>
</dependency>

Gradle

Add this in the build.gradle file:

compile group: 'org.asynchttpclient', name: 'async-http-client', version: '2.12.0'

Let’s now understand how we can handle async requests using the code below:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy