import ballerina/http;
type Args record {|
decimal x;
decimal y;
|};
listener http:Listener h = new (9090);
service /calc on h {
// Resource method arguments can use user-defined types.
// Annotations can be used to refine the mapping between
// Ballerina-declared type and wire format.
resource function post add(@http:Payload Args args)
returns decimal {
return args.x + args.y;
}
}
Resource method typingResource method arguments can use user-defined types.
Listener will use introspection to map from protocol format
(typically JSON) to user-defined type, using |
import ballerina/http;
type Args record {|
decimal x;
decimal y;
|};
listener http:Listener h = new (9090);
service /calc on h {
resource function post add(@http:Payload Args args)
returns decimal {
return args.x + args.y;
}
Resource method arguments can use user-defined types. Annotations can be used to refine the mapping between Ballerina-declared type and wire format.
}
bal run resource_method_typing.bal
curl http://localhost:9090/calc/add -d "{\"x\": 1.0, \"y\": 2.0}"
3.0