This module provides a service for conventient access to Topcoder APIs.
- services.api
- static
- inner
- ~Api
- new Api(base, token)
- .fetch(enpoint, options) ⇒
Promise
- .delete(endpoint, body) ⇒
Promise
- .get(endpoint) ⇒
Promise
- .post(endpoint, body) ⇒
Promise
- .postJson(endpoint, json) ⇒
Promise
- .put(endpoint, body) ⇒
Promise
- .putJson(endpoint, json) ⇒
Promise
- .patch(endpoint, body) ⇒
Promise
- .patchJson(endpoint, json) ⇒
Promise
- .upload(endpoint, body, callback) ⇒
Promise
- ~Api
The default export from the module is Api class.
Kind: static property of services.api
Returns a new or existing Api object for Topcoder API.
Kind: static method of services.api
Returns: Api
- API service object.
Param | Type | Description |
---|---|---|
version | String |
The version of the API. |
token | String |
Optional. Auth token for Topcoder API v2. |
API service object. It is reused for both Topcoder API v2 and v3, as in these cases we are fine with the same interface, and the only thing we need to be different is the base URL and auth token to use.
Kind: inner class of services.api
- ~Api
- new Api(base, token)
- .fetch(enpoint, options) ⇒
Promise
- .delete(endpoint, body) ⇒
Promise
- .get(endpoint) ⇒
Promise
- .post(endpoint, body) ⇒
Promise
- .postJson(endpoint, json) ⇒
Promise
- .put(endpoint, body) ⇒
Promise
- .putJson(endpoint, json) ⇒
Promise
- .patch(endpoint, body) ⇒
Promise
- .patchJson(endpoint, json) ⇒
Promise
- .upload(endpoint, body, callback) ⇒
Promise
Creates a new Api object.
Param | Type | Description |
---|---|---|
base | String |
Base URL of the API. |
token | String |
Optional. Authorization token. |
Sends HTTP request to the specified API endpoint. This method is just a convenient wrapper around isomorphic fetch(..):
-
If API service has auth token, Authorization header is automatically added to the request;
-
If no Content-Type header set in options, it is automatically set to "application/json". In case you want to avoid it, pass null into Content-Type header option.
For additional details see https://github.github.io/fetch/
Kind: instance method of Api
Returns: Promise
- It resolves to the HTTP response object. To get the
actual data you probably want to call .json() method of that object.
Mind that this promise rejects only on network errors. In case of
HTTP errors (404, etc.) the promise will be resolved successfully,
and you should check .status or .ok fields of the response object
to find out the response status.
Param | Type | Description |
---|---|---|
enpoint | String |
Should start with slash, like /endpoint. |
options | Object |
Optional. Fetch options. |
Sends DELETE request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
body | Blob | BufferSource | FormData | String |
Sends GET request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
Sends POST request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
body | Blob | BufferSource | FormData | String |
Sends POST request to the specified endpoint, with JSON payload.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
json | JSON |
Sends PUT request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
body | Blob | BufferSource | FormData | String |
Sends PUT request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
json | JSON |
Sends PATCH request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
body | Blob | BufferSource | FormData | String |
Sends PATCH request to the specified endpoint.
Kind: instance method of Api
Param | Type |
---|---|
endpoint | String |
json | JSON |
Upload with progress
Kind: instance method of Api
Param | Type | Description |
---|---|---|
endpoint | String |
|
body | Object |
and headers |
callback | function |
handler for update progress only works for client side for now |