Java PUT request using Unirest

In this post we will provide some examples on how to make a PUT request using Unirest. Unirest is a lightweight and readable HTTP java client.

Setup:

You will need to add the following dependency:

Put request using Unirest:

Below ¬†are two examples on how to make a REST API call using Unirest, the difference between the two examples is one is asynchronous and the other isn’t.

Example 1:

As you can see from the example above, the API is very readable and fluent. The request is executed when you call asJson(). Other methods include asObject(), asString() and asBinary() depending on your response type.

Example 2:

This second example, is very similar to the first but you can pass a callback object to the asJson() method. This allows it you process the response asynchronously.

In summary, I hope you found this post useful and it helps you in your development.

Similar posts:

  1. POST request using unirest
  2. GET request using unirest
  3. Rest PUT vs POST
  4. How to parse JSON using Jackson
  5. How to parse JSON using GSON

References:

  1. Unirest Documentation

 

 

Leave a Reply