Skip to content

Conversation

@wtetsu
Copy link
Contributor

@wtetsu wtetsu commented Jun 20, 2020

Hello, I added Java code generator that uses java.net.http.HttpClient.

There are already some Java implementations,
but it seems all of them use third party library that are need to be installed.

Advantage:
This code is based on the Java standard library so it's available without installing any third-party library in Java 9+.
and code is concise enough, I think.

Basic code style:

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("http://mockbin.com/har"))
    .header("content-type", "text/plain")
    .method("POST", HttpRequest.BodyPublishers.ofString("Hello World"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

@reynolek reynolek merged commit cb7b688 into Kong:master Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants