Using Uri with Google Maps API
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
Hello
I’m trying to use Uri to create a Google Maps request (https://developers.google.com/maps/documentation/distancematrix/) and i find it a bit awkward since the API uses pipe character for separating parameter values but Uri uses commas and i could not find a way to override it:
utop # open Core.Std;;
utop # #require "uri";;
utop # let x = Uri.of_string "http://www.github.com/";;
val x : Uri.t = <abstr>
utop # let y = Uri.add_query_param x ("origins", ["Bristol"; "Cambridge"; "Plymouth"; "London"]);;
val y : Uri.t = <abstr>
utop # Uri.to_string y;;
- : string = "http://www.github.com/?origins=Bristol,Cambridge,Plymouth,London"
I tried doing this but as you can see it performed character escape on pipe characters (so besides looking ugly it did not work):
utop # String.concat ~sep:"|" ["Bristol"; "Cambridge"; "Plymouth"; "London"];;
- : string = "Bristol|Cambridge|Plymouth|London"
utop # let y = Uri.add_query_param x ("origins", [c]);;
val y : Uri.t = <abstr>
utop # Uri.to_string y;;
- : string = "http://www.github.com/?origins=Bristol%7CCambridge%7CPlymouth%7CLondon"
Help?!
-- Ollie