# Decoding x-www-form-urlencoded

**URL:** <https://discuss.ocaml.org/t/decoding-x-www-form-urlencoded/4505>\
**Category:** Ecosystem\
**Tags:** web\
**Created:** [October 6, 2019, 11:57am UTC](https://discuss.ocaml.org/t/decoding-x-www-form-urlencoded/4505 "2019-10-06T11:57:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [October 6, 2019, 11:57am UTC](https://discuss.ocaml.org/t/decoding-x-www-form-urlencoded/4505/1 "2019-10-06T11:57:28Z")

</div>

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.

```auto
token=gIkuvaNzQIHg97ATvDxqgjtO
&team_id=T0001
&team_domain=example
&enterprise_id=E0001
&enterprise_name=Globular%20Construct%20Inc
&channel_id=C2147483705
&channel_name=test
&user_id=U2147483697
&user_name=Steve
&command=/weather
&text=94070
&response_url=https://hooks.slack.com/commands/1234/5678
&trigger_id=13345224609.738474920.8088930838d88f008e0

```

---

<div class="post-metadata">

**Author:** ![Haudegen](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/haudegen/32/716_2.png) [@Haudegen](https://discuss.ocaml.org/u/Haudegen)\
**Post date:** [October 6, 2019, 12:06pm UTC](https://discuss.ocaml.org/t/decoding-x-www-form-urlencoded/4505/2 "2019-10-06T12:06:48Z")

</div>

> [@lindig](#):
>
> x-www-form-urlencode

[Uri](https://docs.mirage.io/uri/index.html): [val pct\_decode : string → string](https://docs.mirage.io/uri/Uri/index.html)

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [October 6, 2019, 12:08pm UTC](https://discuss.ocaml.org/t/decoding-x-www-form-urlencoded/4505/3 "2019-10-06T12:08:42Z")

</div>

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](https://docs.mirage.io/uri/Uri/index.html#val-query_of_encoded)

```auto
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", ["https://hooks.slack.com/commands/1234/5678"]);
 ("trigger_id", ["13345224609.738474920.8088930838d88f008e0"])]

```

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

---

<div class="post-metadata">

**Author:** ![Khady](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/khady/32/469_2.png) [@Khady](https://discuss.ocaml.org/u/Khady)\
**Post date:** [October 7, 2019, 1:28pm UTC](https://discuss.ocaml.org/t/decoding-x-www-form-urlencoded/4505/4 "2019-10-07T13:28:18Z")

</div>

[https://github.com/ahrefs/atd/pull/194](https://github.com/ahrefs/atd/pull/194)

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