Skip to content

Commit 7cf9870

Browse files
committed
add java async http client
Change-Id: Ic28431ae73b499e929545f95d746b1606fd639f3
1 parent 78789f6 commit 7cf9870

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/targets/java/asynchttp.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @description
3+
* Asynchronous Http and WebSocket Client library for Java
4+
*
5+
* @author
6+
* @windard
7+
*
8+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9+
*/
10+
11+
'use strict'
12+
13+
var CodeBuilder = require('../../helpers/code-builder')
14+
15+
module.exports = function (source, options) {
16+
var opts = Object.assign({
17+
indent: ' '
18+
}, options)
19+
20+
var code = new CodeBuilder(opts.indent)
21+
22+
var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT' ]
23+
24+
code.push('Dsl.asyncHttpClient().prepare%s%s(%s)', source.method.slice(0,1).toUpperCase(), source.method.slice(1).toLowerCase(), source.fullUrl)
25+
26+
// Add headers, including the cookies
27+
var headers = Object.keys(source.allHeaders)
28+
29+
// construct headers
30+
if (headers.length) {
31+
headers.forEach(function (key) {
32+
code.push(1, '.setHeader("%s", "%s")', key, source.allHeaders[key])
33+
})
34+
}
35+
36+
if (source.postData.text) {
37+
code.push(1, '.setBody(%s)', JSON.stringify(source.postData.text))
38+
}
39+
40+
code.push(1, '.execute()')
41+
code.push(1, '.toCompletableFuture()')
42+
code.push(1, '.thenAccept(System.out::println)')
43+
code.push(1, '.join();')
44+
45+
return code.join()
46+
}
47+
48+
module.exports.info = {
49+
key: 'asynchttp',
50+
title: 'AsyncHttp',
51+
link: 'https://github.com/AsyncHttpClient/async-http-client',
52+
description: 'Asynchronous Http and WebSocket Client library for Java'
53+
}

src/targets/java/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ module.exports = {
99
},
1010

1111
okhttp: require('./okhttp'),
12-
unirest: require('./unirest')
12+
unirest: require('./unirest'),
13+
asynchttp: require('./asynchttp'),
14+
1315
}

0 commit comments

Comments
 (0)