Documentation
Enclave SDK
HTTP Request

Making HTTP Requests

Klave SDK provides an interface for you to make HTTP requests from within your application in the secure hardware enclave.

Using HTTP from Applications

Klave SDK provides a simple interface to create and send HTTP request from your application.

⚠️

As querying an HTTP endpoint is not a deterministic operation, HTTP request can only be used in the context of a Query.

The set of operations is the following one:

ClassOperationParametersReturnsBehavior
HTTPrequestHttpRequestHttpResponseExecute and HttpRequest and return an HttpResponse
HTTPrequestAsStringHttpRequestHttpResponse as stringExecute and HttpRequest and return an HttpResponse as a string
HTTPrequestAsArrayBufferHttpRequestHttpResponse as ArrayBufferExecute and HttpRequest and return an HttpResponse as an ArrayBuffer
import { Notifier, JSON, HTTP, HttpRequest } from '@klave/sdk';
import { ErrorMessage, FxRateData, FxRateResult } from './types';
 
/**
 * @query
 */
export function grabFxRates(): void {
 
    const query: HttpRequest = {
        hostname: 'fx.monilytics.org',
        port: 443,
        path: '/?from=USD&to=EUR,GBP,CHF',
        headers: [],
        body: ''
    };
 
    const response = HTTP.request(query);
    if (!response) {
        Notifier.sendJson<ErrorMessage>({
            success: false,
            message: `HTTP call went wrong !`
        });
        return;
    }
 
    const ratesData = JSON.parse<FxRateData>(response.body);
    Notifier.sendJson<FxRateResult>({
        success: true,
        rates: ratesData
    });
};