As far as any Rec.Insert or Rec.Modify can be as valid as if not Rec.Insert then or if not Rec.Modify then you could argue that a plain Client.Get or Client.Post can be equally as valid as if not Client.Get then or if not Client.Post then.
#HTTP CLIENT POST HOW TO#
One argument for this kind of invocation that I heard is almost valid: when a call fails with an error, the runtime error will give you enough context that you’ll know how to handle, just like calling Rec.Insert or another database operation without explicit error handling. It’s naive because it just flatly calls the HTTP endpoint without any error or response handling at all. I called this a “naive way” of invoking REST. (This example is included in the main branch) TempForecast."Max. Temperature" := GetTokenValue(WeatherObject, 'max_temp').AsDecimal() TempForecast."Min. Temperature" := GetTokenValue(WeatherObject, 'min_temp').AsDecimal() TempForecast.Description := GetTokenValue(WeatherObject, 'weather_state_name').AsText() TempForecast.Date := GetTokenValue(WeatherObject, 'applicable_date').AsDate() TempForecast.ID := GetTokenValue(WeatherObject, 'id').AsBigInteger() Something more real-life may look as the src/ file shows: procedure GetForecast(WOEID: Integer var TempForecast: Record "Weather Forecast" temporary)Ĭlient.Get(GetForecastUrl(WOEID), Response) ĬonsolidatedWeather := GetToken(Results, 'consolidated_weather').AsArray() įoreach JToken in ConsolidatedWeather do begin
#HTTP CLIENT POST CODE#
You can follow all code examples on the public GitHub repo that I used during my live session: Naive invocationsĪs I mentioned in the intro, the code example I provided is bare bones for a typical REST invocation. Today’s post is a follow up for my HttpClient Patterns live session on and as I promised, I am providing the text-only version for those who prefer reading to watching. Of course, there are more things there, like headers or perhaps calling HTTP POST (or another method) instead of GET, but when you strip it down to the bones, the chunk above is what remains. DifferentĪuthentication strategies can be added by developers.When invoking any REST web services, a lot of AL code mostly looks like this: procedure CallRESTFoo() They can also be used when constructing Client to createĬake\Http\Client supports a few different authentication systems.
The options parameter is always the 3rd parameter in each of the HTTP methods. Redirect - Number of redirects to follow. Requires $data toĮither be a string, or the _content option to be set when doing GET Type - Send a request body in a custom content type. Timeout - Duration to wait before timing out in seconds. Ssl_cafile - defaults to built in cafile. Validate the SSL certificate against the host name.
#HTTP CLIENT POST VERIFICATION#
Host name verification when verifying SSL certificates (not recommended). Set to false to disable SSL certification The following keys can be used in $options:Īuth - Array of authentication data, the type key is used to delegate toĪn authentication strategy. $http = new Client () $response = $http -> get ( '', , ) Request Method Options ¶Įach HTTP method takes an $options parameter which is used to provideĪddition request information. Send a JSON body in a GET request with query string parameters.