caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Using Uri with Google Distance Matrix API
@ 2013-10-28 21:58 O Frolovs
  2013-10-28 22:26 ` David Sheets
  0 siblings, 1 reply; 2+ messages in thread
From: O Frolovs @ 2013-10-28 21:58 UTC (permalink / raw)
  To: caml-list

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-28 22:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-28 21:58 [Caml-list] Using Uri with Google Distance Matrix API O Frolovs
2013-10-28 22:26 ` David Sheets

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).