Appearance
HTTPClient
HTTP client for making network requests Supports GET, POST, and custom requests with authentication
Methods
get()
javascript
get(url: string, callback: any): voidMake a GET request
Example:
javascript
http.get('https://api.example.com/data', function(result, error) {
if (error) { console.error(error); return; }
console.log(result.status, result.data);
});Parameters:
url(string) - Request URLcallback(any) - Callback function (result, error)
Returns: void
post()
javascript
post(url: string, body: string, callback: any): voidMake a POST request
Example:
javascript
http.post('https://api.example.com/data', JSON.stringify({ name: 'test' }), function(result, error) {
if (error) { console.error(error); return; }
console.log(result.status, result.data);
});Parameters:
url(string) - Request URLbody(string) - Request body stringcallback(any) - Callback function (result, error)
Returns: void
request()
javascript
request(url: string, options: Array<any>, callback: any): voidMake a custom HTTP request
- method: HTTP method (GET, POST, PUT, DELETE, etc.) - headers: Dictionary of HTTP headers - body: Request body string - token: Bearer token for Authorization header - username: Username for Basic auth - password: Password for Basic auth - responseType: Response format - "json" (default), "text", or "base64"
Example:
javascript
// JSON response (default)
var response = await http.request('https://api.example.com/data', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'test' }),
token: 'my-api-key'
});
console.log(response.data.results);
// Binary response as base64 (for audio, images, etc.)
var audio = await http.request('https://api.openai.com/v1/audio/speech', {
method: 'POST',
token: 'sk-...',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'tts-1',
input: 'Hello world',
voice: 'nova',
response_format: 'pcm'
}),
responseType: 'base64'
});
await entity.playAudioBuffer(audio.data, { sampleRate: 24000 });Parameters:
url(string) - Request URLoptions(Array<any>) - Request optionscallback(any) - Callback function (result, error)
Returns: void