-
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
Provide a better way to send with application/x-www-form-urlencoded
#1705
Provide a better way to send with application/x-www-form-urlencoded
#1705
Comments
This can be easily improved as follows. http:Response response = check snowpeak->post("/update",
{
"key1": "value1",
"key2": "value2"
},
mediaType=mime:APPLICATION_FORM_URLENCODED
); Then the underline implementation can do the needful and send it to the back-end. |
I think we can improve the implementation a bit. map<string> pairs = {
"key1": "value1",
"key2": "value2"
};
http:Response response = check snowpeak->post("/update", pairs); If the code is like the above, the user do not need to explicitly mention the media type. We can do a type checking for This also means the below types also will fall under readonly & json j = {key1: "foo", key2: "bar"};
record {|
string key1;
string key2;
|} r = {key1: "foo", key2: "bar"};
record {|
string...;
|} r = {"key1": "foo", "key2": "bar"}; 80% of the time This would also make the inbound and outbound implementations identical. |
The same applies for the service side as well. At the moment a service that consumes and produces // this maps to x-www-form-urlencoded
service / on new http:Listener(9000) {
resource function get foo(@http:Payload map<string> keyvalue)
returns @http:Payload { mediaType: mime:APPLICATION_FORM_URLENCODED} map<string> {
}
} And if we do the improvement as mentioned in the previous comment. It would look like the below. service / on new http:Listener(9000) {
resource function get foo(@http:Payload map<string> keyvalue) returns map<string> {
}
} |
Currently, the default mapping for // this maps to x-www-form-urlencoded
service / on new http:Listener(9000) {
resource function get foo(@http:Payload { mediaType: mime:APPLICATION_FORM_URLENCODED} map<string> keyvalue)
returns @http:Payload { mediaType: mime:APPLICATION_FORM_URLENCODED} map<string> {
}
} |
Fixed via ballerina-platform/module-ballerina-http#968 Binding and the conversion happens based on the diagram of #2530 (comment) |
Description:
At the moment we need to do the following to send a request with
application/x-www-form-urlencoded
.It requires too much code and we need a better way.
The text was updated successfully, but these errors were encountered: