How to use the @jupyterlab/services.ServerConnection.makeRequest function in @jupyterlab/services

To help you get started, we’ve selected a few @jupyterlab/services examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dask / dask-labextension / src / dashboard.tsx View on Github external
export function testDaskDashboard(
    url: string,
    settings: ServerConnection.ISettings
  ): Promise {
    url = normalizeDashboardUrl(url);

    // If this is a url that we are proxying under the notebook server,
    // it is easier to check for a valid dashboard.
    if (URLExt.isLocal(url)) {
      return ServerConnection.makeRequest(
        URLExt.join(settings.baseUrl, url, 'individual-plots.json'),
        {},
        settings
      ).then(response => {
        if (response.status === 200) {
          return true;
        } else {
          return false;
        }
      });
    }

    return new Promise(resolve => {
      // Hack Alert! We would like to test whether a given URL is actually
      // a dask dashboard, since we will be iframe-ing it sight-unseen.
      // However, CORS policies prevent us from doing a normal fetch
github jupyterlab / jupyterlab / tests / test-services / src / serverconnection.spec.ts View on Github external
it('should create a server error from a server response', async () => {
        const settings = getRequestHandler(200, 'hi');
        const init = { body: 'hi', method: 'POST' };
        const response = await ServerConnection.makeRequest(
          settings.baseUrl,
          init,
          settings
        );
        const err = new ServerConnection.ResponseError(response);
        expect(err.message).to.equal('Invalid response: 200 OK');
      });
    });
github dask / dask-labextension / src / clusters.tsx View on Github external
private async _stopById(id: string): Promise {
    const response = await ServerConnection.makeRequest(
      `${this._serverSettings.baseUrl}dask/clusters/${id}`,
      { method: 'DELETE' },
      this._serverSettings
    );
    if (response.status !== 204) {
      const err = await response.json();
      void showErrorMessage('Failed to close cluster', err);
      throw err;
    }
    await this._updateClusterList();
  }
github jupyterlab / jupyterlab / packages / statusbar / src / defaults / memoryUsage.tsx View on Github external
export async function factory(): Promise {
    const request = ServerConnection.makeRequest(
      METRIC_URL,
      {},
      SERVER_CONNECTION_SETTINGS
    );
    const response = await request;

    if (response.ok) {
      try {
        return await response.json();
      } catch (error) {
        throw error;
      }
    }

    return null;
  }
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / statusbar / src / defaults / memoryUsage.tsx View on Github external
export async function factory(): Promise {
    const request = ServerConnection.makeRequest(
      METRIC_URL,
      {},
      SERVER_CONNECTION_SETTINGS
    );
    const response = await request;

    if (response.ok) {
      try {
        return await response.json();
      } catch (error) {
        throw error;
      }
    }

    return null;
  }
github dask / dask-labextension / src / clusters.tsx View on Github external
private async _updateClusterList(): Promise {
    const response = await ServerConnection.makeRequest(
      `${this._serverSettings.baseUrl}dask/clusters`,
      {},
      this._serverSettings
    );
    if (response.status !== 200) {
      const msg =
        'Failed to list clusters: might the server extension not be installed/enabled?';
      const err = new Error(msg);
      if (!this._serverErrorShown) {
        showErrorMessage('Dask Server Error', err);
        this._serverErrorShown = true;
      }
      throw err;
    }
    const data = (await response.json()) as IClusterModel[];
    this._clusters = data;
github jtpio / jupyterlab-heroku / src / heroku.ts View on Github external
function httpRequest(
  url: string,
  method: string,
  request?: Object
): Promise {
  let fullRequest: RequestInit = {
    method: method,
    body: JSON.stringify(request)
  };

  let setting = ServerConnection.makeSettings();
  let fullUrl = URLExt.join(setting.baseUrl, url);
  return ServerConnection.makeRequest(fullUrl, fullRequest, setting);
}
github jupyter / nbdime / packages / nbdime / src / request / index.ts View on Github external
function requestApiPromise(
    baseUrl: string,
    apiPath: string,
    argument: any): Promise {
  const url = URLExt.join(urlRStrip(baseUrl), apiPath);
  let request = {
    method: 'POST',
    body: JSON.stringify(argument),
  };
  let settings = ServerConnection.makeSettings();
  return ServerConnection.makeRequest(url, request, settings)
    .then(handleError);
}