From: O Frolovs <ollie.frolovs.2012@my.bristol.ac.uk>
To: caml-list@inria.fr
Subject: [Caml-list] Using Uri with Google Distance Matrix API
Date: Mon, 28 Oct 2013 21:58:46 +0000 [thread overview]
Message-ID: <CAERFpKUmihcyddM9UprQzKdd7xVA_-ZeCAvD-dH4NXncTFU2=w@mail.gmail.com> (raw)
Hello
I'm learning OCaml and currently trying to use it for my project at uni.
Specifically, i’m trying to use Uri [1] to create a Google Distance
Matrix request 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"
This is not what the API expects.
I also tried concatenating the origins values before passing it to Uri
but as you can see below, Uri performed character escape on pipe
characters. So besides not looking elegant, 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"
I am wondering
(a) if there is a way to make Uri do what i want, that is to use pipe
character to separate the origins values.
(b) why Uri does not have an optional ~sep parameter, like Jane
Street's Core.String.concat does?
Help?!
-- Ollie
[1] http://www.cl.cam.ac.uk/projects/ocamllabs/pkg/uri/1.3.8/index.html
[2] https://developers.google.com/maps/documentation/distancematrix/
next reply other threads:[~2013-10-28 21:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-28 21:58 O Frolovs [this message]
2013-10-28 22:26 ` David Sheets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAERFpKUmihcyddM9UprQzKdd7xVA_-ZeCAvD-dH4NXncTFU2=w@mail.gmail.com' \
--to=ollie.frolovs.2012@my.bristol.ac.uk \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox