Decoding x-www-form-urlencoded

I’m looking for a library that helps decoding application/x-www-form-urlencoded data as it is received by a web server. I assumed that it would be provided by a package like cohttp but could not find it at first glance. Maybe this is known under a different name. It is not difficult to write a decoder but I would simply prefer a battle-hardened one.

1 Like

Uri: val pct_decode : string -> string

The signature for Uri.pct_decode suggests it doesn’t decode forms because the result should be an association. Maybe this?

Uri.query_of_encoded : string -> (string * string list) list

utop # Uri.query_of_encoded req;;
- : (string * string list) list =
[("token", ["gIkuvaNzQIHg97ATvDxqgjtO"]); ("team_id", ["T0001"]);
 ("team_domain", ["example"]); ("enterprise_id", ["E0001"]);
 ("enterprise_name", ["Globular Construct Inc"]);
 ("channel_id", ["C2147483705"]); ("channel_name", ["test"]);
 ("user_id", ["U2147483697"]); ("user_name", ["Steve"]);
 ("command", ["/weather"]); ("text", ["94070"]);
 ("response_url", [""]);
 ("trigger_id", ["13345224609.738474920.8088930838d88f008e0"])]

The name query_of_encoded is unfortunate in that it doesn’t conveys that it is decoding something.


You might be interested by this. Sorry can’t check that it gives exactly the good leads right now.

1 Like