Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add java.net.http.HttpClient based snippet generator #170

Merged
merged 1 commit into from
Jul 22, 2020

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