-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathasynchttp.js
More file actions
55 lines (43 loc) · 1.37 KB
/
asynchttp.js
File metadata and controls
55 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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'
const CodeBuilder = require('../../helpers/code-builder')
module.exports = function (source, options) {
const opts = Object.assign({
indent: ' '
}, options)
const code = new CodeBuilder(opts.indent)
code.push('AsyncHttpClient client = new DefaultAsyncHttpClient();')
code.push(`client.prepare("${source.method.toUpperCase()}", "${source.fullUrl}")`)
// Add headers, including the cookies
const 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'
}