-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redesign HTTP client APIs to expose HTTP errors as Ballerina errors #484
Comments
Design notes document : https://docs.google.com/document/d/1ipV1aaO81I-1WoY9-ost0kK6vyFCcXbUcYoPbXFjWsw/edit?usp=sharing |
@sanjiva Data types public type Payload string|xml|json|byte[]|record {| anydata...; |}|record {| anydata...; |}[];
public type TargetType typedesc<Response|Payload>; Remote function definition public remote function post(string path, RequestMessage message, TargetType targetType = http:Response) returns http:Response|http:Payload|http:ClientError {} Eg: If the user expects payload as a JSON, json payload = <json> check clientEndpoint->post("/get?test=123", request, targetType = json); The issue ballerina-platform/ballerina-spec#386 has mentioned this requirement and the But the http:Client remote functions are not 100% external where it has some ballerina level executions before calling the underneath external function. Most of the important functionalities such as caching, cookie, .. etc are written in ballerina. So if we try to make the client remote function code external, we probably have to rewrite and lose a lot of ballerina code. Therefore still the http:Response response = <http:Response> check clientEndpoint->get("/sayHello"); Please check the BBE related to Client Data Binding Please add thoughts if there are any usability issues |
The required changes are done via
Person person = check backendClient->get("/backend/person"); Hence close the issue. |
HttpClient always returns an HttpResponse currently (unless a low level network error happens).
That is the wrong design as it does not respect the Ballerina design goal of bringing networking aspects into the language. HTTP is a network protocol and an error in that is an error for the programmer.
4XX and 5XX status codes must give errors at the Ballerina level.
The text was updated successfully, but these errors were encountered: