On Tue, 12 Mar 2024 10:46:00 GMT, Michael McMahon <[email protected]> wrote:

> Hi,
> 
> This PR proposes to add simple utility method which returns a simple GET 
> HttpRequest in one call. The current builder pattern requires 4 (or 3 since 
> GET is the default method) method calls to achieve the same effect.
> 
> Thanks,
> Michael

src/java.net.http/share/classes/java/net/http/HttpRequest.java line 91:

> 89:  *
> 90:  *   HttpRequest request = HttpRequest.GET("https://www.foo.com/";);
> 91:  *   String response = client.send(request, 
> BodyHandlers.ofString()).body();

I am not sure whether line 91 is such a good idea. Wouldn't you typically first 
check whether the status is 200 before handling the response? I wonder if we 
could extend HttpResponse to make dealing with this easier?

src/java.net.http/share/classes/java/net/http/HttpRequest.java line 344:

> 342:      * @return a HttpRequest
> 343:      * @throws IllegalArgumentException if the URI scheme is not 
> supported
> 344:      *         or is otherwise invalid.

Did you mean "or if the URI string is otherwise invalid?"
Also we could add an `@spec` here to say the returned value is equivalent to 
`HttpRequest.newBuilder(URI.create(uristring).GET().build()`

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18227#discussion_r1521430252
PR Review Comment: https://git.openjdk.org/jdk/pull/18227#discussion_r1521433214

Reply via email to