src/plugin/iframe_root/modules/api/restClient.js
/**
         * Makes a generic API call to the feeds service.
         * Really, this could probably be used for any RESTish service.
         * It's also really really simple. Just given the method, path,
         * and data, it crafts the REST call by using the Fetch API.
         * If the method isn't one of the usual HTTP verbs (GET, POST, PUT, DELETE),
         * this raises an error.
         * This returns a Promise with either the result of the call de-JSONified,
         * or it raises an error.
         * @param {string} method
         * @param {string} path
         * @param {object} options
         */
Makes a generic API call to the feeds service.
Really, this could probably be used for any RESTish service.
It's also really really simple. Just given the method, path,
and data, it crafts the REST call by using the Fetch API.
If the method isn't one of the usual HTTP verbs (GET, POST, PUT, DELETE),
this raises an error.
This returns a Promise with either the result of the call de-JSONified,
or it raises an error.
Makes a generic API call to the feeds service . Really this could probably be used for any RESTish service . It ' s also really really simple . Just given the method path and data it crafts the REST call by using the Fetch API . If the method isn ' t one of the usual HTTP verbs ( GET POST PUT DELETE ) this raises an error . This returns a Promise with either the result of the call de - JSONified or it raises an error .
makeCall(method, path, data) {
            if (path.startsWith('/')) {
                path = path.substring(1);
            }
            method = method.toLocaleUpperCase();
            if (!['GET', 'POST', 'PUT', 'DELETE'].includes(method)) {
                throw new Error('Method ' + method + ' not usable');
            }
            let url = this.endpoint + path;
            let request = {
                method: method,
                cache: 'no-cache',
                headers: {
                    'Content-type': 'application/json; charset=utf-8',
                    'Authorization': this.token
                },
                redirect: 'follow',
                referrer: 'no-referrer',
                maxRedirects: 5
            };
            if (data) {
                request.body = JSON.stringify(data);
            }
            return fetch(url, request)
                .then(this.handleErrors)
                .then(response => response.json());
        }
makeCall ( method , path , data ) { if ( path . startsWith ( '/' ) ) { path = path . substring ( 1 ) ; } method = method . toLocaleUpperCase ( ) ; if ( ! [ 'GET' , 'POST' , 'PUT' , 'DELETE' ] . includes ( method ) ) { throw new Error ( 'Method ' + method + ' not usable' ) ; } let url = this . endpoint + path ; let request = { method : method , cache : 'no-cache' , headers : { 'Content-type' : 'application/json; charset=utf-8' , 'Authorization' : this . token } , redirect : 'follow' , referrer : 'no-referrer' , maxRedirects : 5 } ; if ( data ) { request . body = JSON . stringify ( data ) ; } return fetch ( url , request ) . then ( this . handleErrors ) . then ( response => response . json ( ) ) ; }
Makes a generic API call to the feeds service.
Makes a generic API call to the feeds service .
// remove the first slash, if present