Skip to content

Files

Latest commit

34456c3 · Feb 4, 2019

History

History
213 lines (152 loc) · 8.16 KB

services.api.md

File metadata and controls

213 lines (152 loc) · 8.16 KB

services.api

This module provides a service for conventient access to Topcoder APIs.

services.api.default

The default export from the module is Api class.

Kind: static property of services.api

services.api.getApi(version, token) ⇒ 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.

services.api~Api

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

new Api(base, token)

Creates a new Api object.

Param Type Description
base String Base URL of the API.
token String Optional. Authorization token.

api.fetch(enpoint, options) ⇒ Promise

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.

api.delete(endpoint, body) ⇒ Promise

Sends DELETE request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String
body Blob | BufferSource | FormData | String

api.get(endpoint) ⇒ Promise

Sends GET request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String

api.post(endpoint, body) ⇒ Promise

Sends POST request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String
body Blob | BufferSource | FormData | String

api.postJson(endpoint, json) ⇒ Promise

Sends POST request to the specified endpoint, with JSON payload.

Kind: instance method of Api

Param Type
endpoint String
json JSON

api.put(endpoint, body) ⇒ Promise

Sends PUT request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String
body Blob | BufferSource | FormData | String

api.putJson(endpoint, json) ⇒ Promise

Sends PUT request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String
json JSON

api.patch(endpoint, body) ⇒ Promise

Sends PATCH request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String
body Blob | BufferSource | FormData | String

api.patchJson(endpoint, json) ⇒ Promise

Sends PATCH request to the specified endpoint.

Kind: instance method of Api

Param Type
endpoint String
json JSON

api.upload(endpoint, body, callback) ⇒ Promise

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