Skip to content
Snippets Groups Projects
Commit a34865ee authored by Joel Cavat's avatar Joel Cavat
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
.idea
.project
.settings
*.DS_Store
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.hepia</groupId>
<artifactId>json-http-example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class App {
public static void main(String[] args) {
try {
String locationsRoute = "http://transport.opendata.ch/v1/locations";
HttpResponse<JsonNode> locations = Unirest.get(locationsRoute)
.queryString("query", "Prairie")
.queryString("type", "station")
.asJson();
String stationBoardRoute = "http://transport.opendata.ch/v1/stationboard";
HttpResponse<JsonNode> stationBoard = Unirest.get(stationBoardRoute)
.queryString("id", "8592890")
.queryString("limit", "5")
.queryString("transportations", "bus")
.queryString("datetime", "2018-11-29 14:00")
.asJson();
System.out.println(stationBoard.getBody().getObject().toString(2));
} catch (UnirestException e) {
e.printStackTrace();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment