Here's my service;
import ballerina/http;
type Album readonly & record {|
string title;
string artist;
|};
type IdNotFound record {|
*http:NotFound;
record {
string message;
} body;
|};
table<Album> key(title) albums = table [
{title: "Blue Train", artist: "John Coltrane"},
{title: "Jeru", artist: "Gerry Mulligan"}
];
service / on new http:Listener(8022) {
resource function get album/[string id]() returns Album|IdNotFound {
if (!albums.hasKey(id)) {
return {body: {message: "No matching resource found."}};
}
return albums.get(id);
}
}
Here's the main.bal ;
import ballerina/http;
import ballerina/io;
type Album readonly & record {
string title;
string artist;
};
type IdNotFound record {|
*http:NotFound;
record {
string message;
} body;
|};
public function main() returns error? {
// Creates a new client with the Basic REST service URL.
http:Client albumClient = check new ("localhost:8022");
string id = "Blue Train";
Album|IdNotFound album = check albumClient->/album/[id];
io:println("GET request:" + album.toJsonString());
}
There's a build error at the Album|IdNotFound album = check albumClient->/album/[id]; line;
incompatible type for parameter 'targetType' with inferred typedesc value: expected 'typedesc<(ballerina/http:2.8.0:Response|anydata)>', found 'typedesc<(wso2healthcare/abc:0.2.3:Album|wso2healthcare/abc:0.2.3:IdNotFound)>'(BCE3931)
How can I get this working?