There is an HTTP service that parses the request body in the HTTP GET request.
How can I use the Ballerina http:Client
to send this request? As per the API docs, it does not have a parameter to pass the request body to the get call.
HTTP GET methods are intended to get data and usually do not include data. That's why the get method does not support having a request message.
HTTP specification neither enforces nor suggests this behavior. So This means it is up to implementing the application web servers to see if it parses the request body in the HTTP GET request.
Although http:Client's get method doesn't support this, you can use the execute method in the http:Client to send data in a GET request.
It invokes an HTTP call with the specified HTTP verb.
Also, if you only need to add the JSON data, then you could directly add it as the request message.
http:Response response = check myClient->execute(<Verb>, <Path>, <JSON payload> }
See the sample below:
import ballerina/http;
import ballerina/io;
type Album readonly & record {
string title;
string artist;
};
public function main() returns error? {
http:Client albumClient = check new ("localhost:9090");
Album albums = check albumClient->execute(http:GET, "/albums", {
title: "Sarah Vaughan and Clifford Brown",
artist: "Sarah Vaughan"
});
io:println("GET request:" + albums.toJsonString());
}