1234567891011121314151617181920212223242526 |
- import { URLExt } from '@jupyterlab/coreutils';
- import { ServerConnection } from '@jupyterlab/services';
- /**
- * Call the API extension
- *
- * @param endPoint API REST end point for the extension
- * @param init Initial values for the request
- * @returns The response body interpreted as JSON
- */
- export async function requestAPI(endPoint = '', init = {}) {
- // Make request to Jupyter API
- const settings = ServerConnection.makeSettings();
- const requestUrl = URLExt.join(settings.baseUrl, 'spellchecker', endPoint);
- let response;
- try {
- response = await ServerConnection.makeRequest(requestUrl, init, settings);
- }
- catch (error) {
- throw new ServerConnection.NetworkError(error);
- }
- const data = await response.json();
- if (!response.ok) {
- throw new ServerConnection.ResponseError(response, data.message);
- }
- return data;
- }
|