Skip to main content
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
return
Promise<RestEntity>
The created REST entity

get()

Retrieves a REST entity by ID.
const entity = await workspace.rest.get('entity-id');
console.log(entity.name, entity.url);
id
string
required
ID of the REST entity
return
Promise<RestEntity>
The REST entity

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}`);
}
return
Promise<RestEntity[]>
Array of REST entities

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);
  }
}
return
Promise<RestTreeItem[]>
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
string
required
ID of the entity to update
data
Partial<RestEntityUpdateOptions>
required
Fields to update (same as RestEntityCreateOptions)
return
Promise<RestEntityData>
The updated entity data

delete()

Deletes a REST entity.
await workspace.rest.delete('entity-id');
id
string
required
ID of the entity to delete
return
Promise<void>
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: '{}',
    },
  }
);
entityId
string
required
ID of the REST entity
script
YasumuEmbeddedScript
required
Script to execute
context
RestScriptContext
required
Execution context with request/response data
return
Promise<unknown>
Script execution result

executeTest()

Executes test scripts for an entity.
const result = await workspace.rest.executeTest(
  'entity-id',
  {
    test: 'expect(response.status).toBe(200);',
  },
  context
);
entityId
string
required
ID of the REST entity
script
YasumuEmbeddedScript
required
Test script to execute
context
RestScriptContext
required
Execution context with request/response data
return
Promise<unknown>
Test execution result

Entity groups

createEntityGroup()

Creates a folder to organize REST entities.
const group = await workspace.rest.createEntityGroup({
  name: 'User Management',
  parentId: null,
});
data
EntityGroupCreateOptions
required
return
Promise<EntityGroupData>
The created entity group

updateEntityGroup()

Updates an entity group.
const updated = await workspace.rest.updateEntityGroup('group-id', {
  name: 'Updated Folder Name',
});
id
string
required
ID of the entity group
data
EntityGroupUpdateOptions
required
Fields to update
return
Promise<EntityGroupData>
The updated entity group

deleteEntityGroup()

Deletes an entity group.
await workspace.rest.deleteEntityGroup('group-id');
id
string
required
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');
entityId
string
required
ID of the REST entity
return
Promise<EntityHistoryData>
The created or updated history entry

deleteHistory()

Deletes history entries for an entity.
await workspace.rest.deleteHistory('entity-id');
entityId
string
required
ID of the REST entity

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()

await entity.delete();

getFullURL()

Returns the complete URL with query parameters and path parameters interpolated.
const fullUrl = entity.getFullURL();
console.log(fullUrl);
return
string | null
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

Build docs developers (and LLMs) love