ballerina-platform/ballerina-library

Introduce a `DefaultStatusCodeResponse` in the `http` module

Closed this issue · 0 comments

Description:

Introduce a status code response record type to map default responses which is described in the OpenAPI specification.

Describe your problem(s)

With the introduction of StatusCodeClient, the response can be mapped to one of the StatusCodeResponse type - This is a union of predefined status code response records.

If there is a response with the status code which is not defined by the user, then that is mapped to an error - ApplicationResponseError and the response body and headers can be found in the details map of this particular error type.

But when we consider the OpenAPI specification, it is common to represent the multiple error response to a default status code response with a defined response body schema. Currently we cannot represent this directly in the client call. Users has to extract the error and get the error details to build the default response.

http:StatusCodeClient clientEP = check new("localhost:9090/api");
OkAlbumArray|error res = clientEP->/albums;

if res is http:ApplicationResponseError {
    http:Detail details = res.detail();
}

Describe your solution(s)

As a solution, we can introduce a new status code response record - DefaultStatusCodeResponse which can be used to map all the other status code responses which are not defined by the user.

http:StatusCodeClient clientEP = check new("localhost:9090/api");
OkAlbumArray|DefaultStatusCodeResponse|error res = clientEP->/albums;