Making Asynchronous Http Request using Dispatch

Knoldus

Dispatch is a library for asynchronous HTTP interaction. It allows us to make asynchronous Http request to the url. If there is a REST API, and you want to hit it from your code, its the thing that you are looking for.

For getting started, you have to add its dependency inside the build.sbt

DispatcherDependencies

Now you are good to go to use them inside your project.

Making HTTP Calls.

We’ll start with a very simple request.

Request

Here we define 5 seconds maximum to fetch the response from the API, if the response is not returned we get a TimeoutException

If we do not want to specify the wait time, and allow it to wait till the response comes. We can easily do that by using
[[scala.concurrent.duration.Duration.Inf Duration.Inf]] for unbounded waiting.

Making HTTPS Requests and Configuring the HttpMethods.

We can also define HTTPS request by defining

URL secure

But this does not solve…

View original post 135 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s