The RestModule provides methods to create, update, and execute REST API requests within a workspace.
Access the module
Access the REST module through a workspace instance:
const workspace = yasumu.workspaces.getActiveWorkspace();
const restModule = workspace.rest;
// Create an entity
const entity = await restModule.create({
name: 'Get Users',
url: 'https://api.example.com/users',
method: 'GET',
});
Methods
create()
Creates a new REST entity.
const entity = await workspace.rest.create({
name: 'Create User',
url: 'https://api.example.com/users',
method: 'POST',
headers: [
{ key: 'Content-Type', value: 'application/json', enabled: true },
],
body: JSON.stringify({ name: 'John Doe' }),
});
data
RestEntityCreateOptions
required
Show RestEntityCreateOptions properties
HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
searchParameters
Array<{key: string, value: string, enabled: boolean}>
URL query parameters
requestParameters
Array<{key: string, value: string, enabled: boolean}>
URL path parameters (e.g., :id in /users/:id)
Pre-request and post-request scripts
get()
Retrieves a REST entity by ID.
const entity = await workspace.rest.get('entity-id');
console.log(entity.name, entity.url);
list()
Lists all REST entities in the workspace.
const entities = await workspace.rest.list();
for (const entity of entities) {
console.log(`${entity.method} ${entity.name}`);
}
listTree()
Returns REST entities organized in a tree structure with folders.
const tree = await workspace.rest.listTree();
for (const item of tree) {
if (item.type === 'folder') {
console.log('Folder:', item.name);
} else {
console.log('Entity:', item.name);
}
}
Tree structure of folders and entities
update()
Updates a REST entity.
const updated = await workspace.rest.update('entity-id', {
name: 'Updated Name',
url: 'https://api.example.com/v2/users',
});
ID of the entity to update
data
Partial<RestEntityUpdateOptions>
required
Fields to update (same as RestEntityCreateOptions)
delete()
Deletes a REST entity.
await workspace.rest.delete('entity-id');
ID of the entity to delete
Resolves when the entity is deleted
executeScript()
Executes a pre-request or post-request script for an entity.
const result = await workspace.rest.executeScript(
'entity-id',
{
preRequest: 'console.log("Before request");',
postRequest: 'console.log("After request");',
},
{
request: {
url: 'https://api.example.com/users',
method: 'GET',
headers: {},
},
response: {
status: 200,
headers: {},
body: '{}',
},
}
);
script
YasumuEmbeddedScript
required
Script to execute
context
RestScriptContext
required
Execution context with request/response data
executeTest()
Executes test scripts for an entity.
const result = await workspace.rest.executeTest(
'entity-id',
{
test: 'expect(response.status).toBe(200);',
},
context
);
script
YasumuEmbeddedScript
required
Test script to execute
context
RestScriptContext
required
Execution context with request/response data
Entity groups
createEntityGroup()
Creates a folder to organize REST entities.
const group = await workspace.rest.createEntityGroup({
name: 'User Management',
parentId: null,
});
data
EntityGroupCreateOptions
required
Show EntityGroupCreateOptions properties
ID of parent folder, or null for root level
updateEntityGroup()
Updates an entity group.
const updated = await workspace.rest.updateEntityGroup('group-id', {
name: 'Updated Folder Name',
});
data
EntityGroupUpdateOptions
required
Fields to update
deleteEntityGroup()
Deletes an entity group.
await workspace.rest.deleteEntityGroup('group-id');
ID of the entity group to delete
History management
listHistory()
Lists execution history for REST entities.
const history = await workspace.rest.listHistory();
for (const item of history) {
console.log(item.entityId, item.timestamp);
}
return
Promise<EntityHistoryData[]>
Array of history entries
upsertHistory()
Creates or updates a history entry for an entity.
const entry = await workspace.rest.upsertHistory('entity-id');
return
Promise<EntityHistoryData>
The created or updated history entry
deleteHistory()
Deletes history entries for an entity.
await workspace.rest.deleteHistory('entity-id');
RestEntity class
The RestEntity class represents a single REST API request.
Properties
const entity = await workspace.rest.get('entity-id');
console.log(entity.id);
console.log(entity.name);
console.log(entity.url);
console.log(entity.method);
Methods
setName()
await entity.setName('New Name');
setUrl()
await entity.setUrl('https://api.example.com/v2/users');
setMethod()
await entity.setMethod('POST');
update()
await entity.update({
name: 'Updated Name',
headers: [
{ key: 'Authorization', value: 'Bearer token', enabled: true },
],
});
delete()
getFullURL()
Returns the complete URL with query parameters and path parameters interpolated.
const fullUrl = entity.getFullURL();
console.log(fullUrl);
The complete URL with parameters, or null if no URL is set
executePreRequestScript()
await entity.executePreRequestScript({
request: {
url: entity.url,
method: entity.method,
headers: {},
},
});
toJSON()
const data = entity.toJSON();
console.log(data);
Example usage
// Create REST entities
const getUsers = await workspace.rest.create({
name: 'Get Users',
url: 'https://api.example.com/users',
method: 'GET',
headers: [
{ key: 'Accept', value: 'application/json', enabled: true },
],
searchParameters: [
{ key: 'page', value: '1', enabled: true },
{ key: 'limit', value: '10', enabled: true },
],
});
const getUser = await workspace.rest.create({
name: 'Get User by ID',
url: 'https://api.example.com/users/:id',
method: 'GET',
requestParameters: [
{ key: 'id', value: '123', enabled: true },
],
});
console.log(getUser.getFullURL());
// Output: https://api.example.com/users/123
// Organize with folders
const userGroup = await workspace.rest.createEntityGroup({
name: 'User Endpoints',
parentId: null,
});
// Update entity to move it to the group
await getUsers.update({
groupId: userGroup.id,
});
// List all entities
const entities = await workspace.rest.list();
console.log(`Total entities: ${entities.length}`);
// Get tree view
const tree = await workspace.rest.listTree();
Workspace
Workspace management
Schema parser
Parse REST entity schemas