Connection
Main class that is used to establish a connection and send requests to target sites.
Properties
Name | Type | Description |
---|---|---|
headers | Array.<{name: String, value: String}> | A list of headers. |
url | string | The URL of the target site for the connection. Can be empty, as you can specify the URI as a parameter for any request method. |
Constructors
Connection
Creates an object that lets you establish a connection with a target site.
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL of the target site for the connection. Can be empty, as you can specify the URI as a parameter for any request method. |
sslKeyName | string | Optional name of the SSL key that is used to establish a secure connection. If you don't want to specify this parameter, pass 'null'. |
timeout | int | Optional parameter that specifies the connection timeout for outgoing HTTP requests in milliseconds. |
See Also
doSync
Methods
addHeader
Adds a new header to the current connection.
Parameters
Name | Type | Description |
---|---|---|
header | Object, string | A header object with the structure {name: string, value: string}. If the value parameter is specified separately, the provided string is used as the name of the header. |
value | string | The value that is assigned to the header. Only considered when the first parameter is specified as a string. |
Return Value
Type | Description |
---|---|
Connection | The current connection object. |
basicAuth
Adds an authorization header with the value returned by the Base64.encode(login + ':' + password) function.
Parameters
Name | Type | Description |
---|---|---|
login | String | The login to use for the authorization request. |
password | String | The password to use for the authorization request. |
Return Value
Type | Description |
---|---|
Connection | The current connection object. |
bearerAuth
Adds an authorization header with the value in "Bearer" format ('Bearer ' + token).
Parameters
Name | Type | Description |
---|---|---|
token | String | The token to use for the authorization request. |
Return Value
Type | Description |
---|---|
Connection | The current connection object. |
connectSync
Executes a synchronous CONNECT request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
deleteSync
Executes a synchronous DELETE request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
doSync
Sends a synchronous HTTP request. Note that instead of passing a proper request type with this method, there are dedicated methods that correspond to each request type that you can call directly. For example, getSync or postSync.
Parameters
Name | Type | Description |
---|---|---|
requestType | string | A valid HTTP request type. For a list of supported request types, see REQUEST_TYPES. |
uri | string | A relative URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}> | The query parameters. |
payload | string, Array, Object | The payload to be sent in the request. |
Return Value
Type | Description |
---|---|
Response | An object that represents the HTTP response. |
getSync
Executes a synchronous GET request.
Parameters
Name | Type | Description |
---|---|---|
uri | String | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
headSync
Executes a synchronous HEAD request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
optionsSync
Executes a synchronous OPTIONS request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
patchSync
Executes a synchronous PATCH request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
payload | string | The payload to be sent in the request. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
postSync
Executes a synchronous POST request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. If the payload parameter is empty, the query parameters are passed as a form entity. |
payload | string, Object | The payload to be sent in the request. For posting attachment files from YouTrack to a third-party application, pass the payload as an object, set its `type` value to 'multipart/form-data', and pass the attachments in `parts`. For each part, `name`, `size`, `fileName`, and `content` values are required. See an example of such a request below. For details, see Posting Binary Content with multipart/form-data Type |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
Example
putSync
Executes a synchronous PUT request.
Parameters
Name | Type | Description |
---|---|---|
uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. If the payload parameter is empty, the query parameters are passed as a form entity. |
payload | string | The payload to be sent in the request. |
Return Value
Type | Description |
---|---|
Response | An object that represents an HTTP response. |
setHeader
Sets a header to the current connection. If such header already exists, its value is updated.
Parameters
Name | Type | Description |
---|---|---|
header | Object, string | A header object with the structure {name: string, value: string}. If the value parameter is specified separately, the provided string is used as the name of the header. |
value | string | The value that is assigned to the header. Only considered when the first parameter is specified as a string. |
Return Value
Type | Description |
---|---|
Connection | The current connection object. |