Http module
The http module provides a set of methods to interact with the HTTP protocol.
Import the module with:
import { http } from 'lib';
Get(url:string, headers: Dictionary<string,string>) :
This method performs an HTTP GET request to the specified URL.
Arguments
stringurl: The URL to request.Dictionary<string,string>headers: An optional dictionary of headers to send with the request.
Returns
HttpResponseThe response object containing the content and headers.
Example
import { http, console } from 'lib';
// 1. Prepare request headers
var headers = {
"Accept": "application/json",
"User-Agent": "Vista-Macro-Engine/1.0",
"Authorization": "Bearer MON_TOKEN_API"
};
// 2. Create request
var response = http.Get("https://jsonplaceholder.typicode.com/todos/1", headers);
// 3. Use response
// The raw content (string) of the request is accessible via response.Content
var rawContent = response.Content;
// This content is a JSON string,
var data = JSON.parse(rawContent);
// On peut par exemple assigner cette donnée à un élément Vista
// (ex: Shape.Name = data.title)
console.Write("Title retrieved from API: " + data.title);
// 4. Read response headers
var contentType = response.Headers["Content-Type"];
console.Write("Le format de la réponse est : " + contentType);