ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

No status code constants for redirects #3801

Open shafreenAnfar opened 1 year ago

shafreenAnfar commented 1 year ago

The below is available for 200 OK

# The common status code response constant of `Ok`.
public final readonly & Ok OK = {};

But not the same for redirects such as

# The status code response record of `TemporaryRedirect`.
#
# + status - The response status code obj
public type TemporaryRedirect record {|
    *CommonResponse;
    readonly StatusTemporaryRedirect status = STATUS_TEMPORARY_REDIRECT_OBJ;
|};

# The status code response record of `PermanentRedirect`.
#
# + status - The response status code obj
public type PermanentRedirect record {|
    *CommonResponse;
    readonly StatusPermanentRedirect status = STATUS_PERMANENT_REDIRECT_OBJ;
|};

Also, when it comes to redirects location header is so common. Therefore, we can do the below,

# The status code response record of `TemporaryRedirect`.
#
# + status - The response status code obj
public type TemporaryRedirect record {|
    *CommonResponse;
     string location;
    readonly StatusTemporaryRedirect status = STATUS_TEMPORARY_REDIRECT_OBJ;
|};

# The status code response record of `PermanentRedirect`.
#
# + status - The response status code obj
public type PermanentRedirect record {|
    *CommonResponse;
     string location;
    readonly StatusPermanentRedirect status = STATUS_PERMANENT_REDIRECT_OBJ;
|};
shafreenAnfar commented 1 year ago

It should help simply the below BBE too.

https://pre-prod.ballerina.io/learn/by-example/http-service-redirects/