Low-level HTTP request abstraction for communicating with the Jupyter Lab server. The RequestHandler class provides GET, POST, PUT, and DELETE methods with built-in error handling, user feedback dialogs, and support for long-running requests.
import { RequestHandler } from "@elyra/application";
import { Dialog } from '@jupyterlab/apputils';Service class for making requests to the Jupyter Lab server with comprehensive error handling.
/**
* Service class for making requests to the jupyter lab server.
*/
class RequestHandler {
/**
* Make a GET request to the jupyter lab server.
* @param requestPath - The url path for the request. This path is appended to the base path of the server.
* @param longRequest - Whether the request is expected to take a long time. If true, displays a dialog warning.
* @returns A promise that resolves with the server response on success or an error dialog result on failure.
*/
static makeGetRequest(requestPath: string, longRequest: boolean): Promise<any>;
/**
* Make a POST request to the jupyter lab server.
* @param requestPath - The url path for the request. This path is appended to the base path of the server.
* @param requestBody - The body of the request. Will be included in the RequestInit object.
* @param longRequest - Whether the request is expected to take a long time. If true, displays a dialog warning.
* @returns A promise that resolves with the server response on success or an error dialog result on failure.
*/
static makePostRequest(requestPath: string, requestBody: any, longRequest: boolean): Promise<any>;
/**
* Make a PUT request to the jupyter lab server.
* @param requestPath - The url path for the request. This path is appended to the base path of the server.
* @param requestBody - The body of the request. Will be included in the RequestInit object.
* @param longRequest - Whether the request is expected to take a long time. If true, displays a dialog warning.
* @returns A promise that resolves with the server response on success or an error dialog result on failure.
*/
static makePutRequest(requestPath: string, requestBody: any, longRequest: boolean): Promise<any>;
/**
* Make a DELETE request to the jupyter lab server.
* @param requestPath - The url path for the request. This path is appended to the base path of the server.
* @param longRequest - Whether the request is expected to take a long time. If true, displays a dialog warning.
* @returns A promise that resolves with the server response on success or an error dialog result on failure.
*/
static makeDeleteRequest(requestPath: string, longRequest: boolean): Promise<any>;
/**
* Make a request to the jupyter lab server.
* @param requestPath - The url path for the request. This path is appended to the base path of the server.
* @param requestInit - The initialization options for the request. A RequestInit object that must include a value for method.
* @param longRequest - Whether the request is expected to take a long time. If true, displays a dialog warning.
* @returns A promise that resolves with the server response on success or an error dialog result on failure.
*/
static makeServerRequest(requestPath: string, requestInit: RequestInit, longRequest: boolean): Promise<any>;
}Make GET requests to retrieve data from the Jupyter Lab server.
/**
* Make a GET request to the jupyter lab server.
* @param requestPath - The url path for the request
* @param longRequest - Whether to show a wait dialog for long operations
* @returns Promise resolving with server response or error dialog result
*/
static makeGetRequest(requestPath: string, longRequest: boolean): Promise<any>;Usage Examples:
import { RequestHandler } from "@elyra/application";
// Simple GET request
const response = await RequestHandler.makeGetRequest('elyra/schema/code-snippets', false);
// Long-running GET request with wait dialog
const largeData = await RequestHandler.makeGetRequest('elyra/export/large-dataset', true);Make POST requests to create new resources on the Jupyter Lab server.
/**
* Make a POST request to the jupyter lab server.
* @param requestPath - The url path for the request
* @param requestBody - The body of the request
* @param longRequest - Whether to show a wait dialog for long operations
* @returns Promise resolving with server response or error dialog result
*/
static makePostRequest(requestPath: string, requestBody: any, longRequest: boolean): Promise<any>;Usage Examples:
import { RequestHandler } from "@elyra/application";
// Create new metadata
const newMetadata = {
schema_name: 'code-snippet',
display_name: 'My Snippet',
name: 'my-snippet',
metadata: { language: 'Python', code: ['print("hello")'] }
};
const result = await RequestHandler.makePostRequest(
'elyra/metadata/code-snippets',
JSON.stringify(newMetadata),
false
);Make PUT requests to update existing resources on the Jupyter Lab server.
/**
* Make a PUT request to the jupyter lab server.
* @param requestPath - The url path for the request
* @param requestBody - The body of the request
* @param longRequest - Whether to show a wait dialog for long operations
* @returns Promise resolving with server response or error dialog result
*/
static makePutRequest(requestPath: string, requestBody: any, longRequest: boolean): Promise<any>;Usage Examples:
import { RequestHandler } from "@elyra/application";
// Update existing metadata
const updatedMetadata = {
schema_name: 'code-snippet',
display_name: 'Updated Snippet',
name: 'my-snippet',
metadata: { language: 'Python', code: ['print("updated")'] }
};
const result = await RequestHandler.makePutRequest(
'elyra/metadata/code-snippets/my-snippet',
JSON.stringify(updatedMetadata),
false
);Make DELETE requests to remove resources from the Jupyter Lab server.
/**
* Make a DELETE request to the jupyter lab server.
* @param requestPath - The url path for the request
* @param longRequest - Whether to show a wait dialog for long operations
* @returns Promise resolving with server response or error dialog result
*/
static makeDeleteRequest(requestPath: string, longRequest: boolean): Promise<any>;Usage Examples:
import { RequestHandler } from "@elyra/application";
// Remove metadata
await RequestHandler.makeDeleteRequest('elyra/metadata/code-snippets/my-snippet', false);Core method for making requests with custom RequestInit options.
/**
* Make a request to the jupyter lab server.
* @param requestPath - The url path for the request
* @param requestInit - The initialization options including method
* @param longRequest - Whether to show a wait dialog for long operations
* @returns Promise resolving with server response or error dialog result
*/
static makeServerRequest(requestPath: string, requestInit: RequestInit, longRequest: boolean): Promise<any>;All RequestHandler methods include automatic error handling:
The error dialogs are implemented using JupyterLab's dialog system and Elyra's expandable error components.