Skip to main content

LensStudio:RemoteServiceModule

Module

Class for interacting with Snap's RemoteServiceModule.

Class for interacting with Snap's RemoteServiceModule. Unlike "LensStudio:Network".performHttpRequestWithReply, the API requests done here are to specific endpoints that have been registered with Snap.

Example

// The LensStudio:RemoteServiceModule provides performApiRequest() for calling
// Snap-registered API endpoints. Unlike generic HTTP requests via LensStudio:Network,
// these target specific specs identified by a specId.
//
// Workflow:
// 1. Create a RemoteApiRequest via RemoteApiRequest.create()
// 2. Set endpoint, specId, parameters, and optional body
// 3. Call performApiRequest(request, callback) to execute
// 4. Callback receives a RemoteApiResponse with statusCode, body, linkedResources

const { RemoteApiRequest, performApiRequest } = await import('LensStudio:RemoteServiceModule');

const request = RemoteApiRequest.create();
request.endpoint = '/v1/example-endpoint';
request.specId = 'example-spec-id';
request.parameters = { key: 'value' };

console.log('Created RemoteApiRequest via static create().');
console.log('endpoint:', request.endpoint);
console.log('specId:', request.specId);
console.log('parameters:', JSON.stringify(request.parameters));

performApiRequest(request, (response) => {
console.log('Response statusCode:', response.statusCode);
console.log('Response body length:', response.body.toBytes().length);
console.log('Linked resources count:', response.linkedResources.length);
});

console.log('Dispatched performApiRequest — callback will fire on completion.');

Namespaces

NamespaceDescription
RemoteApiResponse-

Classes

ClassDescription
RemoteApiRequestConfiguration for request through "LensStudio:RemoteServiceModule".performApiRequest
RemoteApiResponseResponse object from RemoteServiceModule API requests.

Functions

FunctionDescription
performApiRequestPerform the API request.