Skip to main content

LensStudio:Network.HttpReply

Class

Handle to an in-progress HTTP request returned by performHttpRequestWithReply; must be retained to keep the connection alive.

Index

Example

// HttpReply is returned by performHttpRequestWithReply and exposes
// three signals: onData, onEnd, and onError for streaming responses.
const { HttpRequest, performHttpRequestWithReply } = await import('LensStudio:Network');

const request = new HttpRequest();
request.url = 'https://httpbin.org/get';
request.method = HttpRequest.Method.Get;

const reply = performHttpRequestWithReply(request);

// onData fires for each chunk of response data (Editor.Buffer)
this.connections.push(
reply.onData.connect((chunk: Editor.Buffer) => {
console.log('Received data chunk:', chunk.toString().length, 'chars');
})
);

// onEnd fires once with the final HttpResponse when complete
this.connections.push(
reply.onEnd.connect((response: import('LensStudio:Network').HttpResponse) => {
console.log('Request complete, status:', response.statusCode);
console.log('Content-Type:', response.contentType);
})
);

// onError fires if the request fails
this.connections.push(
reply.onError.connect((response: import('LensStudio:Network').HttpResponse) => {
console.log('Request error:', response.error);
})
);

console.log('HttpReply created with onData, onEnd, onError signals connected');

Extends

Properties

onData

readonly onData: signal1<Buffer, void>

Signal fired when a chunk of response data is received, providing an Editor.Buffer with the chunk contents.


onEnd

readonly onEnd: signal1<HttpResponse, void>

Signal fired when the HTTP response has fully completed, providing the final HttpResponse.


onError

readonly onError: signal1<HttpResponse, void>

Signal fired when the HTTP request encounters an error, providing the HttpResponse with error details.

Methods

getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame