-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjget.java
More file actions
executable file
·42 lines (39 loc) · 1.23 KB
/
Copy pathjget.java
File metadata and controls
executable file
·42 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.konghq:unirest-java:3.14.5
import kong.unirest.GetRequest;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
public class jget {
public static void main(String[] args) {
String url = null;
boolean getJson = false;
for (int i=0; i<args.length;) {
String arg = args[i++];
switch (arg) {
case "--json":
getJson = true;
break;
default:
url = arg;
break;
}
}
if (url == null) {
System.out.println("Usage: jget [--json] <url>");
System.exit(-1);
}
int status;
GetRequest req = Unirest.get(url);
if (getJson) {
HttpResponse<JsonNode> response = req.asJson();
System.out.println(response.getBody().toPrettyString());
status = response.getStatus();
} else {
HttpResponse<String> response = req.asString();
System.out.println(response.getBody());
status = response.getStatus();
}
System.exit(status == 200 ? 0 : 1);
}
}