reddit_api is a set OCaml client libraries for Reddit's API.
reddit_api_kernel provides:
reddit_api_async provides a client for sending these requests to Reddit and some utilities for common usage patterns. It handles authentication and Reddit's rate-limiting headers.
Here. I recommend the Reddit_api_kernel.Endpoint and Reddit_api_async.Connection modules as entry points.
let print_links credentials =
let connection = Connection.create credentials ~user_agent:"Link printer" in
let subreddit =
Subreddit_name.combine (List.map ~f:Subreddit_name.of_string [ "ocaml"; "redditdev" ])
in
let%bind link_listing =
Connection.call_exn connection (Endpoint.top ~since:Year ~subreddit ())
in
let links = Listing.children link_listing in
List.iter links ~f:(fun link ->
print_s
[%sexp
{ title : string = Thing.Link.title link
; url : string option = Option.map (Thing.Link.url link) ~f:Uri.to_string
; author : Username.t option = Thing.Link.author link
; score : int = Thing.Link.score link
}]);
return ()Encode knowledge, documented or otherwise, about correct usage of the API via the type system.
Provide workarounds when we get the above wrong:
Connection.call_raw function that allows users to access HTTP responses directly.Be perfect
Express "unexpected" Reddit behavior in the type system.
(_, [`couldn't_parse_response]) Result.t).Thanks to PRAW for providing innumerable examples of Reddit API client code.