handler.js 886 B

1234567891011121314151617181920212223242526
  1. import { URLExt } from '@jupyterlab/coreutils';
  2. import { ServerConnection } from '@jupyterlab/services';
  3. /**
  4. * Call the API extension
  5. *
  6. * @param endPoint API REST end point for the extension
  7. * @param init Initial values for the request
  8. * @returns The response body interpreted as JSON
  9. */
  10. export async function requestAPI(endPoint = '', init = {}) {
  11. // Make request to Jupyter API
  12. const settings = ServerConnection.makeSettings();
  13. const requestUrl = URLExt.join(settings.baseUrl, 'spellchecker', endPoint);
  14. let response;
  15. try {
  16. response = await ServerConnection.makeRequest(requestUrl, init, settings);
  17. }
  18. catch (error) {
  19. throw new ServerConnection.NetworkError(error);
  20. }
  21. const data = await response.json();
  22. if (!response.ok) {
  23. throw new ServerConnection.ResponseError(response, data.message);
  24. }
  25. return data;
  26. }