{
"ID": "2bdaad2e-e6f4-49d1-b737-e0276d8ccc03",
"name": "simple-config",
"metadata": {},
"secret_type": "Opaque",
"environment_id": "b1402013-b080-488d-858b-dadcb07a551a",
"data": null
}
Above JSON is the response from an HTTP client. We have an HTTP service and within that service, we call the above HTTP client and prepare a minimized response from the above JSON. The expected minimized response is,
{
"ID": "2bdaad2e-e6f4-49d1-b737-e0276d8ccc03",
"name": "simple-config"
}
Please find the relevant code below.
public type ResponseDto record {
string ID;
string name;
};
isolated resource function get () {
var httpClient = check getHttpClient();
string endpoint = string `/v1/external/api`;
var headers = utils:createHeaders(ctx);
json response = check httpClient->get(endpoint, headers, targetType = json);
ResponseDto res = check response.cloneWithType();
return res;
}
Still, I am getting full response and not getting the minimized response. How do I resolve this issue?
The
ResponseDtocan hold additional fields other thanIDandname. That is exactly what happens here as well.CloneWithTypedoes not loose data.In the above code, we are mapping data with the required fields.