4.0.4 • Published 3 years ago

@shiftboard/api-client v4.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Shiftboard API Client

wercker status

A Shiftboard API client.

Install

yarn add @shiftboard/api-client

# Git
yarn add git+ssh://git@github.com:shiftboard/shiftboard-api-js.git

Running Tests

To run the unit tests:

yarn test

Usage

// Import library
import { apiClient } from '@shiftboard/api-client'
// or use the default export
import apiClient from '@shiftboard/api-client'

// Optionally, identify the app that is calling the API
const options = {
  'User-Agent': 'my-special-client'
}

// Create an instance of the client that accepts a baseURL, API key, secret, and options
const mySystemAPI = apiClient(baseURL, apiKey, apiSecret, options)

// Call your own methods
mySystemAPI
  .get(methodName, params)
  // Returns server response
  .then((response) => response.data)

// Create a user API instance
const myUserAPI = apiClient(baseURL, apiKey, apiSecret, options)

For live examples:

  • Review the helpers in the example.js file and run with node example.js
  • Review the helpers in the sandbox.js file and run with babel-node sandbox.js

Responses

The responses are promise-based, so you will need to handle things in a .then() function.

The promise is always resolved with a response object, except if there was a problem with the request! This is one of the goals of this library. It ensures errors are handled in .catch and have 2 separate flows.

A response will always have these 2 properties:

ok      - Boolean - True if API returns a `result` object or a non-200 status code
problem - String  - A message about what went wrong

If the request made it to the server and got a response of any kind, response will also have these properties:

data     - Object - this is probably the thing you're after.
status   - Number - the HTTP response code
headers  - Object - the HTTP response headers
config   - Object - the `axios` config object used to make the request
duration - Number - the number of milliseconds it took to run this request

Bravo

npm.io

4.0.4

3 years ago

4.0.3

4 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.0

7 years ago