YouTrack Standalone 2017.2 Help

Connection

Main class which is used for establishing a connection and making requests to target sites.

// Get a content of a PasteBin paste, assuming that we have somehow received its key (`pasteBinKey`). var connection = new http.Connection('http://pastebin.com/raw/'); connection.addHeader({name: Content-Type, value: text/plain}); var response = connection.getSync(pasteBinKey, ''); if (response && response.code === 200) { var text = ''; response.headers.forEach(function(header) { text += header.name + ': ' + header.value + '\n'; }); text += '\n' + response.response; issue.addComment(text); }

Constructors

 

Connection

Connection(url, sslKeyName, timeout)

Initiate a new connection.

See also:

  • doSync

Parameters:

NameTypeDescription
url string url of target site to connect. Can be empty, as a uri is passed to request methods.
sslKeyName string optional name of ssl key, which is required for connection.
timeout int optional parameter to specify read timeout for outgoing http requests

 

Properties

NameTypeDescriptionRead-only
headers Array.<{name: String, value: String}> list of headers.
url string url of target site to connect. Can be empty, as a uri is passed to request methods.

Methods

 

addHeader

addHeader(header, value)

Add a new header to a current connection.

Parameters:

NameTypeDescription
header Object, string header object with the following structure: {name: string, value: string} or a string in case the second parameter is also used.
value string header value. Only considered when the first argument is a string.

Returns:

TypeDescription
Connection this connection instance

 

basicAuth

basicAuth(login, password)

Adds an Authorization header with value Base64.encode(login + ':' + password).

Parameters:

NameTypeDescription
login String login to use.
password String password to use.

Returns:

TypeDescription
Connection this connection instance.

 

connectSync

connectSync(uri, queryParams)

Executes synchronous CONNECT request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

deleteSync

deleteSync(uri, queryParams)

Executes synchronous DELETE request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

doSync

doSync(requestType, uri, queryParams, payload)

Sends a synchronous HTTP request. Note that instead of passing a proper request typeyou can call a corresponding method, like `getSync(uri, queryParams)` etc.

Parameters:

NameTypeDescription
requestType string a valid HTTP request type. REQUEST_TYPES can be located in an appropriate constant.
uri string relative URI. A complete URL is a concatenation of a string passed to Connection constructor and this string.
queryParams Array.<{name: String, value: String}> query parameters.
payload string, Array, Object a payload to be sent.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

getSync

getSync(uri, queryParams)

Executes synchronous GET request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri String request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

headSync

headSync(uri, queryParams)

Executes synchronous HEAD request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

optionsSync

optionsSync(uri, queryParams)

Executes synchronous OPTIONS request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

patchSync

patchSync(uri, queryParams, payload)

Executes synchronous PATCH request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names.
payload string request payload.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

postSync

postSync(uri, queryParams, payload)

Executes synchronous POST request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names. In case the payload parameter is empty, query parameters are passed as a form entity.
payload string request payload.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

putSync

putSync(uri, queryParams, payload)

Executes synchronous PUT request.

See also:

  • doSync for parameters and return value descriptions.

Parameters:

NameTypeDescription
uri string request URI.
queryParams Array.<{name: String, value: String}>, Object query parameters. In case an object is passed,its keys are considered to be parameter names. In case the payload parameter is empty, query parameters are passed as a form entity.
payload string request payload.

Returns:

TypeDescription
Response an object representing an HTTP response.

 

Last modified: 9 August 2017