3.6.5 • Published 2 years ago

cubic-client v3.6.5

Weekly downloads
17
License
MIT
Repository
github
Last release
2 years ago

cubic-client

npm build dependencies

Installation

npm install cubic-client

Usage

const Client = require('cubic-client')
const client = new Client()

cubic.get('/foo').then(res => console.log(res.body)) // bar

Configuration

const Client = require('cubic-client')
const client = new Client({key: value})
KeyDefaultDescription
api_url'http://localhost:3003/'URL of cubic API-Node to connect to
auth_url'http://localhost:3030/'URL of cubic Auth-Node to authenticate with
user_keynullUser key obtained via Auth-Node registration
user_secretnullUser secret obtained via Auth-Node

API

client.awaitConnection()

Returns a promise that resolves once the client is fully connected.

client.isConnected()

Returns a boolean wether the connection is up or not.

RESTful methods

client.query(verb, query)

Sends a GET request to the API-Node

ArgumentDescriptionDefault
verbRESTful verb. e.g. GET.None
queryRequest query, either string or body object.None
client.get(url)

Sends a GET request to the API-Node

ArgumentDescriptionDefault
urlURL to request, without domain. e.g. /foo.None
client.post(url, body)

Sends a POST request to the API-Node

ArgumentDescriptionDefault
urlURL to request, without domain. e.g. /foo.None
bodyData to send to endpoint. Can be any data type.None
client.put(url, body)

Sends a PUT request to the API-Node

ArgumentDescriptionDefault
urlURL to request, without domain. e.g. /foo.None
bodyData to send to endpoint. Can be any data type.None
client.patch(url, body)

Sends a PATCH request to the API-Node

ArgumentDescriptionDefault
urlURL to request, without domain. e.g. /foo.None
bodyData to send to endpoint. Can be any data type.None
client.delete(url, body)

Sends a DELETE request to the API-Node

ArgumentDescriptionDefault
urlURL to request, without domain. e.g. /foo.None
bodyData to send to endpoint. Can be any data type.None

Pub/Sub

client.subscribe(endpoint, fn)

Subscribe to updates on a specific endpoint.

ArgumentDescriptionDefault
endpointURL to listen for updates on, without domain. e.g. '/foo'None
fnFunction to run when updates are received. Takes the new data as argument.None
client.unsubscribe(endpoint)

Unsubscribe to updates on a specific endpoint.

ArgumentDescriptionDefault
endpointURL that you are currently subscribed to, without domain. e.g. '/foo'None

Authentication

client.login(user, secret)

Re-authorizes as a specific user at runtime. Usually users should be logged in through the constructor options.

ArgumentDescriptionDefault
userUser id, equal to user_key when registering.None
secretUser password, equal to user_secret when registering.None
client.setRefreshToken(token)

Manually set the refresh token. This way user credentials needn't be exposed.

ArgumentDescriptionDefault
tokenrefresh_token to use.None
client.getRefreshToken()

Retrieve current refresh token. Will await any existing authentication process. Useful if the initial login can be done through user/pass but the refresh token needs to be stored for subsequent logins.

client.setAccessToken(token)

Manually set the access token. This will expire on the next refresh.

ArgumentDescriptionDefault
tokenaccess_token to use.None
client.getRefreshToken()

Retrieve current access token. Will await any existing authentication process.

License

MIT

3.6.5

2 years ago

3.6.4

4 years ago

3.6.3

4 years ago

3.6.2

4 years ago

3.6.1

4 years ago

3.6.0

4 years ago

3.4.3

4 years ago

3.5.3

4 years ago

3.5.2

4 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.4.2

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.1

5 years ago

2.1.0

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago