README
NSApiClient
Project that handles requests and authentication with NSAPI
Installation
Using npm:
$ npm i @nslibs/nsapi-client
Using cdn:
<script src="https://unpkg.com/@nslibs/nsapi-client@0.0.2/dist/nsapi-client.js"></script>
Usage
let nsapi = new NSApiClient(url, {
api_key,
session_id,
retry_limit: 3, // limit # of retries before throwing err
retry_delay: 1000, // ms to wait between request attempts
});
Node.js
let NSApiClient = require('@nslibs/nsapi-client');
let nsapi = new NSApiClient('https://example.com/graphql');
try {
await nsapi.login("user", "password");
let res = await nsapi.request({
query,
variables, //optional
api_key, //optional
session_id, //optional
});
} catch (err) {
console.log(err); // => NSApiError: There was an error
}
Browser
<script src="unpkg.com/@nslibs/nsapi-client"></script>
<script>
let nsapi = new NSApiClient('https://example.com/graphql');
try {
await nsapi.login("id", "password");
return await nsapi.request({
query,
variables, //optional
api_key, //optional
session_id, //optional
});
} catch (err) {
alert(err.message);
}
</script>