Panflux Javascript SDK
This is the Javascript client library (SDK) for consuming Panflux APIs.
Install
# Choose your flavor of package manager:
yarn add @panflux/sdk
# or
npm i --save @panflux/sdk
Usage
Load the client class:
const {Client} = require('@panflux/sdk');
// or
import Client from '@panflux/sdk';
Initialize the client:
const client = Client.init({
clientID: 'your-id',
clientSecret: 'your-secret',
tokenURL: 'endpoint-if-not-default'
})
Do a simple query:
client.query('query { me { id, name } }')
.then(({data, errors}) => {
if (errors) {
console.log(errors);
}
if (data) {
console.info(`Authenticated as ${data.me.name}`);
}
});
Or with variables:
client.query('query result($id: UUID!) { user(id: $id) { id, name } }', {
'id' => 'your-user-id',
}).then(({data}) => {
console.info(`Authenticated as ${data.result.name}`);
});
Subscribe to ping tests:
client.subscribe('subscription { ping }',
data => console.info(data),
err => console.error(err),
() => console.info('Subscription closed'),
})
.then(subscription => {
setTimeout(() => subscription.unsubscribe(), 5000);
});
License
MIT, see the included LICENSE file.