HTTP Client
JavaScript HTTP client library for a Plugin
Remarks
The PATCH, POST, & PUT requests allow data
to be supplied as either a string, byte array, or JavaScript object. For JavaScript Object data, unless the 'content-type' header is explicitly set, it will be understood as JSON Content & will automatically set the 'content-type' to 'application/json'. If the JavaScript Object data is Form URL Encoded Content you will need to explicitly set the 'content-type' header to 'application/x-www-form-urlencoded'
Example
Methods
get
Send a GET request to the specified URL.
get(url, [options])
url
: Relative or absolute URL for the request.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
delete
Send a DELETE request to the specified URL.
delete(url, [options])
url
: Relative or absolute URL for the request.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
head
Send a HEAD request to the specified URL.
head(url, [options])
url
: Relative or absolute URL for the request.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
options
Send a OPTIONS request to the specified URL.
options(url, [options])
url
: Relative or absolute URL for the request.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
post
Send a POST request to the specified URL.
post(url, data, [options])
url
: Relative or absolute URL for the request.data
: The HTTP Content sent to the server. Can be a string, Object, or byte array.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
put
Send a PUT request to the specified URL.
put(url, data, [options])
url
: Relative or absolute URL for the request.data
: The HTTP Content sent to the server. Can be a string, Object, or byte array.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
patch
Send a PATCH request to the specified URL.
patch(url, data, [options])
url
: Relative or absolute URL for the request.data
: The HTTP Content sent to the server. Can be a string, Object, or byte array.options
baseURL
: Will be prepended tourl
unlessurl
is absolute.headers
: An object containing the HTTP request headers.auth
: Authentication credentials for the request.responseType
: The type of data returned by the request: 'arraybuffer', 'json', 'text', 'xml'. (default: 'json')followRedirects
: Boolean that indicates whether it will follow redirection responses. (default: true)timeout
: Time, in milliseconds, to wait before timing out. The default is 0 which waits indefinitely.
Returns an HTTP Response Object
Response Object
All HTTP requests return a response object with the following properties:
Property | Description |
---|---|
data | The response content. Will either be a string, JSON object, or XML object. |
status | A integer representing the status code returned from the server |
statusText | A string representing the status description returned from the server |
headers | An object containing HTTP response headers. |
Auth Object
Property | Description |
---|---|
username | The username for the HTTP request. |
password | The password for the HTTP request. |
authType | The type of authentication used: 'auto', 'basic', 'digest'. (default: 'auto') |