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

Latest commit

 

History

History
History
54 lines (42 loc) · 1.38 KB

File metadata and controls

54 lines (42 loc) · 1.38 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
* @description
* HTTP code snippet generator for Java using Unirest.
*
* @author
* @shashiranjan84
*
* 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)
var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ]
if (methods.indexOf(source.method.toUpperCase()) === -1) {
code.push('HttpResponse<String> response = Unirest.customMethod("%s","%s")', source.method.toUpperCase(), source.fullUrl)
} else {
code.push('HttpResponse<String> response = Unirest.%s("%s")', source.method.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, '.header("%s", "%s")', key, source.allHeaders[key])
})
}
if (source.postData.text) {
code.push(1, '.body(%s)', JSON.stringify(source.postData.text))
}
code.push(1, '.asString();')
return code.join()
}
module.exports.info = {
key: 'unirest',
title: 'Unirest',
link: 'http://unirest.io/java.html',
description: 'Lightweight HTTP Request Client Library'
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.