Calling a Web API from Java using Unirest - Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.vainolo.examples.javahttpapiclient; | |
import com.mashape.unirest.http.HttpResponse; | |
import com.mashape.unirest.http.JsonNode; | |
import com.mashape.unirest.http.Unirest; | |
public class JavaHTTPAPIClient { | |
public void getQuestionsUsingUnirest() throws Exception { | |
HttpResponse<JsonNode> response = Unirest.get("https://api.stackexchange.com/2.2/questions"). | |
header("accept", "application/json"). | |
queryString("order","desc"). | |
queryString("sort", "creation"). | |
queryString("filter", "default"). | |
queryString("site", "stackoverflow"). | |
asJson(); | |
System.out.println(response.getBody().getObject().toString(2)); | |
} | |
public static void main(String args[]) throws Exception { | |
JavaHTTPAPIClient client = new JavaHTTPAPIClient(); | |
client.getQuestionsUsingUnirest(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment