This file contains the settings and the communication mechanism for the ITSLanguage REST API.
- Source:
Members
(static, constant) settings
- Source:
The settings to use for the communication with the ITSLanguage API.
(inner, constant) APPLICATION_JSON :string
- Source:
Content-Type HTTP Header value.
Type:
- string
(inner, constant) AUTHORIZATION :string
- Source:
Authorization HTTP Header key.
Type:
- string
(inner, constant) CONTENT_TYPE :string
- Source:
Content-Type HTTP Header key.
Type:
- string
(inner, constant) LINK :string
- Source:
Link header value.
Type:
- string
Methods
(static) addAccessToken(urlopt) → {string}
- Source:
Add an access token to a given URL.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url |
string |
<optional> |
''
|
The URL to add an access token to. |
Returns:
An url with the access token appended.
- Type
- string
(static) authorisedRequest(method, url, bodyopt, headersopt) → {Promise.<Object>}
- Source:
Perform an HTTP request with the desired method, body, and headers to the given partial ITSLanguage API URL.
This request will add the Authorization header to the request.
This function only allows to make calls to the ITSLanguage API.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
method |
string | The request METHOD ('GET', 'POST', 'PUT', 'DELETE'). |
|
url |
string | The location to send the request to. |
|
body |
* |
<optional> |
Anything which needs to be sent somewhere. |
headers |
Headers |
<optional> |
Extra headers to send with the request. |
Throws:
-
- When the given
urlparam is not a partial URL, or when there is no authorisation token available.
- When the given
- Type
- Promise.<string>
Returns:
- The response from the ITSLanguage API.
- Type
- Promise.<Object>
(static) request(method, url, bodyopt, headersopt) → {Promise.<Object>}
- Source:
Perform an HTTP request for the given method, url, body, and headers.
In case the given url is a partial url, meaning it starts with a /, the base URL to the
ITSLanguage API is prepended.
When a Object instance is provided as body, it'll be transformed into JSON. Unless it is either a
URLSearchParams or a FormData object. Anything else is sent as plain text.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
method |
string | The request METHOD ('GET', 'POST', 'PUT', 'DELETE'). |
|
url |
string | The location to send the request to. |
|
body |
* |
<optional> |
Anything which needs to be sent somewhere. |
headers |
Headers |
<optional> |
Extra headers to send with the request. |
Returns:
The response of the made request.
- Type
- Promise.<Object>
(static) updateSettings(newSettings)
- Source:
Update the settings with the newSettings.
Parameters:
| Name | Type | Description |
|---|---|---|
newSettings |
Object | The settings to inject/update. |
Throws:
-
- When the given
newSettingsis something other than a object.
- When the given
- Type
- Error
(inner) getBearerToken() → {string}
- Source:
Build a bearer token from the authorizationToken in the settings object.
Throws:
-
When no authorizationToken is set.
- Type
- Error
Returns:
The generated bearer token.
- Type
- string
(inner) handleResponse(response) → {Promise|Response}
- Source:
Parse the response of a fetch request.
Try to parse the given response body as JSON, if it isn't Leave the response as is.
Parameters:
| Name | Type | Description |
|---|---|---|
response |
Response | The response to parse. |
Throws:
-
-
- When the request wasn't okay and the contents of the response isn't json.
- Type
- Promise.<string>
-
-
-
- When the request wasn't okay and the contents of the response is json.
- Type
- Promise.<Error>
-
Returns:
- The contents of a JSON response or the response itself if the body is something other than JSON.
- Type
- Promise | Response