Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
reynolek merged 1 commit intoKong:masterKong/httpsnippet:masterfrom
wtetsu:feature/add_javanethttpwtetsu/httpsnippet:feature/add_javanethttpCopy head branch name to clipboard
Jul 22, 2020
Merged

Add java.net.http.HttpClient based snippet generator#170
reynolek merged 1 commit intoKong:masterKong/httpsnippet:masterfrom
wtetsu:feature/add_javanethttpwtetsu/httpsnippet:feature/add_javanethttpCopy head branch name to clipboard

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.