1.0.5 • Published 8 months ago

@keyos/api-sdk v1.0.5

Weekly downloads
25
License
MIT
Repository
-
Last release
8 months ago

KeyOS API SDK For Javascript

Thanks to Allah for supporting this Project.

Crafted with 💙 by Herlangga Sefani

Github repository : https://github.com/gaibz/KeyOS-sdk-javascript

Project started at end of March 2020

Installation

npm install @keyos/api-sdk  

API Documentation

Complete api documentation can be found on KeyoS Documentation API

Usage & Example REST

Initialization

const { Rest } = require("@keyos/api-sdk");
let RestApi = new Rest.Api();

Example GET Request : Search City or Subdistrict

documentation can be found in : KeyOS Documentation City or Subdistrict

RestApi.action('GET', 'location/city_or_subdistrict', {
    q : "tasikmalaya" // q is the request parameter, see doc
}).then((response) => {
    // if request success this code will firing
    // response.getStatusCode() for get status code
    // response.getStatusText() for get status text
    // response.getBody() for get response body
    console.log({response});
}).catch((error) => {
    // in case we have some error
    // error.getStatusCode() for get status code
    // error.getStatusText() for get status text
    // error.getBody() for get response body
    console.log({error});
}).finally(() => {
    // this block is optional, and will fired after then and catch finished
});

If you want some more Object Oriented way (This will also trigger autocompletion if your text editor support it) :

let request = new Rest.ApiRequest();
request.setPath('location/city_or_subdistrict')
    .setMethod(Rest.METHOD.GET)
    .setRequestQuery({q : 'tasikmalaya'});

RestApi.call(request).then((response) => {
    console.log({response});
}).catch((error) => {
    console.log("error");
    console.log(error);
});

Example POST Request : Login / Auth

documentation can be found in : KeyOS Documentation Admin Login

// we will pass the third parameter since we dont have to specify query parameter
// the fourth parameter is the request body
RestApi.action('POST', 'auth', {}, {
    username : '<some_admin_username>',
    password : '<some_admin_password>',
    roles : 'ADMIN'
}).then((response) => {
    // if request success this code will firing
    // response.getStatusCode() for get status code
    // response.getStatusText() for get status text
    // response.getBody() for get response body
    console.log({response});
}).catch((error) => {
    // in case we have some error
    // error.getStatusCode() for get status code
    // error.getStatusText() for get status text
    // error.getBody() for get response body
    console.log({error});
}).finally(() => {
    // this block is optional, and will fired after then and catch finished
});

Object Oriented Style :

let request = new Rest.ApiRequest();
// method chaining style
request.setPath('location/city_or_subdistrict')
.setMethod(Rest.METHOD.GET)
.setRequestBody({
    username : '<some_admin_username>',
    password : '<some_admin_password>',
    roles : 'ADMIN'
});

RestApi.call(request).then((response) => {
    console.log({response});
}).catch((error) => {
    console.log("error");
    console.log(error);
}).finally(() => {
    // This block is optional and will firing after then and catch executed
    // normally this is promise based
});
1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.1

2 years ago

1.0.0

2 years ago

0.4.2

3 years ago

0.3.2

5 years ago

0.3.3

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.1.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0-rc2

5 years ago

0.0.0-rc1

5 years ago

0.0.0-alpha2

5 years ago

0.0.0-alpha1

5 years ago