-
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
Proposal: Data-binding for application/x-www-form-urlencoded
#2530
Comments
After having a discussion with @chamil321 @ayeshLK @lnash94, we decided to do a slight improvement to the proposal. We decided to update the mapping as follows for inbound requests.
|
I think we can look at the problem in a different angle as well. We can look at it as inbound and outbound. This proposal is related to inbound messages. The inbound message can be branched as follows. This basically means we are not limiting a given Ballerina type to a specific mime type. For instance |
One question regarding the unknown content-type, |
application/www-x-form-urlencoded
application/x-www-form-urlencoded
@nadeeshaan It is dynamic and will be inferred by looking at the Ballerina type. |
The existing implementation solely depend on the ballerina type and does not check the content type except for the Case 1: resource function 'default body3(http:Caller caller, @http:Payload json person) returns error? {
jsonval1 = check person.name;
} Error : Conclusion: String to Json casting is avoided. Check the table to understand the allowed payloads for each type |
Fixed as per the table #2700 (comment). Hence closed |
Summary
application/x-www-form-urlencoded
is common MIME type in use. It allows you to send key/value pairs in the payload. This proposal is to provide data binding for such payload. Both on listener side as well as the client side.Goals
application/x-www-form-urlencoded
Motivation
As mentioned in the summary section
application/x-www-form-urlencoded
is used to send key/value pairs in the entity body. However, Ballerina does not provide a direct data binding for such payload. Therefore, users have to either do string manipulation or usehttp:Request
object'sgetFormParams()
function. But it is not the best user experience. This is applicable for both the listener side as well as the client side.User experience can be radically improved by introducing data binding for such payloads as discussed in the next section.
Description
Since
application/x-www-form-urlencoded
is about key/value pairs, the appropriate Ballerina data binding ismap<string>
. This is applicable for both listener and client side. However, users could usemap<string>
forjson
payloads as well. Following table shows the mapping and the payload.Since
map<string>
maps into two different types of payloads, implementation must try parsing the payload in both ways to make sure the payload cannot be mapped tomap<string>
. However,map<string>
is quite common in theapplication/x-www-form-urlencoded
scenario than theapplication/json
scenario. Therefore, implementation always must try first parsing the payload forapplication/x-www-form-urlencoded
and if it fails must try parsing the payload forapplication/json
.Listener
On the listener side users should be able to do following when dealing with such payload.
As mentioned earlier, since two types of payloads could map into
map<string>
, as a performance optimization users can be specific as follows.Client
On the client side the user experience should be as follows.
As on the listener side, there is no room for performance optimization on the client side. This is because on the client side there is no place to mention what type payload the user is expecting.
Anyway, it is worth noting that as mentioned earlier 80% case would be the users are trying to map
application/x-www-form-urlencoded
tomap<string>
. Therefore, there is very little gains to make with such optimizations.The text was updated successfully, but these errors were encountered: