-
Enhancement
-
Resolution: Rejected
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Provide a command-line tool to do basic http requests.
Motivation
Different Operating Systems come with a variety of http clients, all or none of which may be installed. In order to retrieve and install shell based 3rd party software is is common practice now to do something like curl https://.../install.sh | sh. However curl is not available in all environments. To install java based tools and single file scripts it would be nice to be able to provide a single command that users could definitively execute since they would already have the jdk.
Additionally this tool would be useful for interacting with jwebserver.
I believe at this time only support for GET is needed, but it may be useful to support other basic functionality. Such as content, headers, and maybe support for basic auth encoding. I do not see the need for a client as complex as curl, in the same vein as jwebserver is not servlets.
Pretty close to the simplest thing that could possibly work is `jhttp get http://...`.
```
#!/usr/bin/env -S java --source 11
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
class JHTTP {
public static void main(String... args) {
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.method(args[0].toUpperCase(), HttpRequest.BodyPublishers.noBody())
.uri(URI.create(args[1]))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
```
Since this is my first proposal, if needed I can update or try to write a full JEP.
Provide a command-line tool to do basic http requests.
Motivation
Different Operating Systems come with a variety of http clients, all or none of which may be installed. In order to retrieve and install shell based 3rd party software is is common practice now to do something like curl https://.../install.sh | sh. However curl is not available in all environments. To install java based tools and single file scripts it would be nice to be able to provide a single command that users could definitively execute since they would already have the jdk.
Additionally this tool would be useful for interacting with jwebserver.
I believe at this time only support for GET is needed, but it may be useful to support other basic functionality. Such as content, headers, and maybe support for basic auth encoding. I do not see the need for a client as complex as curl, in the same vein as jwebserver is not servlets.
Pretty close to the simplest thing that could possibly work is `jhttp get http://...`.
```
#!/usr/bin/env -S java --source 11
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
class JHTTP {
public static void main(String... args) {
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.method(args[0].toUpperCase(), HttpRequest.BodyPublishers.noBody())
.uri(URI.create(args[1]))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
```
Since this is my first proposal, if needed I can update or try to write a full JEP.