This repository contains Async integrated OCaml bindings for the DuckDuckGo API.
The DuckDuckGo
module exports three functions you can use
to issue DuckDuckGo queries.
query
which returns astring
query_json
which returns aYojson.Basic.json
query_record
which returns aDuckDuckGo.response
We can use query_record
to query DuckDuckGo about OCaml. Here's
query_record
's simplified type:
string -> (DuckDuckGo.response, exn) Core.Std.Result.t Async.Std.Deferred.t
query_record
takes in a query string and returns a deferred
DuckDuckGo.response
result. We can use Async's try_with
to unwrap the
result and print the response of the query.
DuckDuckGo.query_record "ocaml" >>| function
| Ok response -> print_endline response.abstract
| Error _ -> print_endline "no abstract found"
For more complete examples, please refer to the examples directory.
Documentation can be found online at http://mwhittaker.github.io/duckduckgo-ocaml/. Alternatively, you can build the documentation yourself:
make doc && firefox doc.docdir/index.html
You can install these dependencies using opam
:
opam install core async atdgen cohttp textwrap uri yojson