1.0.7 • Published 5 years ago

@infotechnohelp/api-client v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Implementation

\

    const api = new Api("<?= \Cake\Routing\Router::url('/', true); ?>", "api/",
        "<?= $this->request->getParam('_csrfToken'); ?>");

    if (api instanceof Api === false) {
        throw Error('constant `api` is not an instance of `Api`');
    }

\

Send requests

getJson(url, successCallback, errorCallback, apiRoot)

\

    api.getJson("test/get", function(successResponse){
        console.log(successResponse);
    }, function(failureResponse){
        console.log(failureResponse);
    });

\

postJson(url, successCallback, errorCallback, apiRoot)

\

    api.postJson("test/get", {key: value}, function(successResponse){
        console.log(successResponse);
    }, function(failureResponse){
        console.log(failureResponse);
    });

\

Clone api and set specific path

\

var newApi = api.clone();
        trackerApi.setApiRoot("any/api/path");

\