forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
19 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @description | ||
* Asynchronous Http and WebSocket Client library for Java | ||
* | ||
* @author | ||
* @windard | ||
* | ||
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author. | ||
*/ | ||
|
||
'use strict' | ||
|
||
var CodeBuilder = require('../../helpers/code-builder') | ||
|
||
module.exports = function (source, options) { | ||
var opts = Object.assign({ | ||
indent: ' ' | ||
}, options) | ||
|
||
var code = new CodeBuilder(opts.indent) | ||
|
||
code.push('AsyncHttpClient client = new DefaultAsyncHttpClient();') | ||
|
||
code.push(`client.prepare${source.method[0].toUpperCase()}${source.method.substring(1).toLowerCase()}("${source.fullUrl}")`) | ||
|
||
// Add headers, including the cookies | ||
var headers = Object.keys(source.allHeaders) | ||
|
||
// construct headers | ||
if (headers.length) { | ||
headers.forEach(function (key) { | ||
code.push(1, '.setHeader("%s", "%s")', key, source.allHeaders[key]) | ||
}) | ||
} | ||
|
||
if (source.postData.text) { | ||
code.push(1, '.setBody(%s)', JSON.stringify(source.postData.text)) | ||
} | ||
|
||
code.push(1, '.execute()') | ||
code.push(1, '.toCompletableFuture()') | ||
code.push(1, '.thenAccept(System.out::println)') | ||
code.push(1, '.join();') | ||
code.blank() | ||
code.push('client.close();') | ||
|
||
return code.join() | ||
} | ||
|
||
module.exports.info = { | ||
key: 'asynchttp', | ||
title: 'AsyncHttp', | ||
link: 'https://github.com/AsyncHttpClient/async-http-client', | ||
description: 'Asynchronous Http and WebSocket Client library for Java' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/fixtures/output/java/asynchttp/application-form-encoded.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "application/x-www-form-urlencoded") | ||
.setBody("foo=bar&hello=world") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "application/json") | ||
.setBody("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("cookie", "foo=bar; bar=baz") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePropfind("http://mockbin.com/har") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") | ||
.setHeader("cookie", "foo=bar; bar=baz") | ||
.setHeader("accept", "application/json") | ||
.setHeader("content-type", "application/x-www-form-urlencoded") | ||
.setBody("foo=bar") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.prepareGet("http://mockbin.com/har") | ||
.setHeader("accept", "application/json") | ||
.setHeader("x-foo", "Bar") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.prepareGet("https://mockbin.com/har") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
10 changes: 10 additions & 0 deletions
10
test/fixtures/output/java/asynchttp/jsonObj-multiline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "application/json") | ||
.setBody("{\n \"foo\": \"bar\"\n}") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
10 changes: 10 additions & 0 deletions
10
test/fixtures/output/java/asynchttp/jsonObj-null-value.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "application/json") | ||
.setBody("{\"foo\":null}") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") | ||
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--\r\n") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") | ||
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
10 changes: 10 additions & 0 deletions
10
test/fixtures/output/java/asynchttp/multipart-form-data.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") | ||
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.prepareGet("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.prepareGet("http://mockbin.com/har") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AsyncHttpClient client = new DefaultAsyncHttpClient(); | ||
client.preparePost("http://mockbin.com/har") | ||
.setHeader("content-type", "text/plain") | ||
.setBody("Hello World") | ||
.execute() | ||
.toCompletableFuture() | ||
.thenAccept(System.out::println) | ||
.join(); | ||
|
||
client.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
require('should') | ||
|
||
module.exports = function (snippet, fixtures) {} |