-
Notifications
You must be signed in to change notification settings - Fork 0
Erlang
PiotrFerenc edited this page May 14, 2024
·
1 revision
-module(example).
-export([main/0]).
-define(URL, "http://localhost:5000/execute").
-record(parameters, {console_text}).
-record(task_item, {sequence, name, action}).
-record(request_payload, {parameters, tasks}).
main() ->
Payload = #request_payload{
parameters = #parameters{console_text = <<"hallo word">>},
tasks = [#task_item{sequence = 1, name = <<"log">>, action = <<"console">>}]
},
JsonContent = jsx:encode(Payload),
ContentType = {"Content-Type", "application/json"},
Headers = [ContentType],
{ok, RequestBody} = httpc:request(post, { ?URL, Headers, "application/json", JsonContent }, [], []),
case RequestBody of
{ok, {{_, 200, _}, _, ResponseBody}} ->
io:format("Response: ~s~n", [ResponseBody]);
{ok, {{_, StatusCode, _}, _, _}} ->
io:format("Error: ~p~n", [StatusCode]);
Error ->
io:format("Error: ~p~n", [Error])
end.