LensStudio:Network.HttpResponse
ClassAn HTTP response, received from the callback to performing a request, such as through: "LensStudio:Network".performHttpRequestWithReply, or "LensStudio:Remot…
An HTTP response, received from the callback to performing a request, such as through: "LensStudio:Network".performHttpRequestWithReply, or "LensStudio:RemoteServiceModule".performApiRequest.
Index
Properties
Example
// HttpResponse is received via the onEnd/onError signals of HttpReply,
// or through the callback of performHttpRequest.
// It exposes: body, contentType, error, headers, statusCode (all readonly).
const { HttpRequest, performHttpRequest } = await import('LensStudio:Network');
const request = new HttpRequest();
request.url = 'https://httpbin.org/get';
request.method = HttpRequest.Method.Get;
performHttpRequest(request, (response: import('LensStudio:Network').HttpResponse) => {
// statusCode: HTTP status (e.g. 200, 404, 500)
console.log('Status code:', response.statusCode);
// contentType: MIME type of the response body
console.log('Content-Type:', response.contentType);
// headers: response headers as a key-value object
console.log('Headers:', JSON.stringify(response.headers));
// body: response body as an Editor.Buffer — use toBytes() or toString()
console.log('Body length:', response.body.toString().length, 'chars');
// error: non-empty string if the request failed
if (response.error) {
console.log('Error:', response.error);
} else {
console.log('Request succeeded with no errors');
}
});
console.log('Sent HTTP GET request to inspect HttpResponse properties');
Properties
body
readonlybody:Buffer
The body of this response.
contentType
readonlycontentType:string
The content type of this response.
error
readonlyerror:string
The error of this response, if applicable.
headers
readonlyheaders:any
The headers of this response.
statusCode
readonlystatusCode:number
The HTTP status code of this response.