Skip to content

Latest commit

 

History

History
99 lines (77 loc) · 3.33 KB

File metadata and controls

99 lines (77 loc) · 3.33 KB
title description ms.author ms.date ms.topic author ms.reviewer
HttpClient.Get(Text, var HttpResponseMessage) Method
Sends a GET request to get the resource identified by the request URL.
solsen
05/14/2024
reference
SusanneWindfeldPedersen
solsen

HttpClient.Get(Text, var HttpResponseMessage) Method

Version: Available or changed with runtime version 1.0.

Sends a GET request to get the resource identified by the request URL.

Syntax

[Ok := ]  HttpClient.Get(Path: Text, var Response: HttpResponseMessage)

Parameters

HttpClient
 Type: HttpClient
An instance of the HttpClient data type.

Path
 Type: Text
The path the request is sent to.

Response
 Type: HttpResponseMessage
The response received from the remote endpoint.

Return Value

[Optional] Ok
 Type: Boolean
Accessing the HttpContent property of HttpResponseMessage in a case when the request fails will result in an error. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Ways that HttpClient.Get calls can fail

The method HttpClient.Get can fail and return false in the following ways:

[!INCLUDEhttpclientFailureReasonsList]

Example (HTTP GET)

A GET request shouldn't send a body and is used (as the method name indicates) to retrieve (or get) data from a resource. To make an HTTP GET request, given an HttpClient and a URI, use the HttpClient.Get method:

    local procedure GetRequest() ResponseText: Text
    var
        Client: HttpClient;
        IsSuccessful: Boolean;
        Response: HttpResponseMessage;
        ResponseText: Text;
    begin
        IsSuccessful := Client.Get('https://jsonplaceholder.typicode.com/todos/3', Response);

        if not IsSuccessful then begin
            // handle the error
        end;

        if not Response.IsSuccessStatusCode() then begin
            HttpStatusCode := response.HttpStatusCode();
            // handle the error (depending on the HTTP status code)
        end;

        Response.Content().ReadAs(ResponseText);

        // Expected output:
        //   GET https://jsonplaceholder.typicode.com/todos/3 HTTP/1.1
        //   {
        //     "userId": 1,
        //     "id": 3,
        //     "title": "fugiat veniam minus",
        //     "completed": false
        //   }
    end;

The preceding code:

Supported HTTP methods

[!INCLUDESupportedHTTPmethods]

See Also

Call external services with the HttpClient data type
HttpClient Data Type
Get Started with AL
Developing Extensions