Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=50ed16b67568e3407e3b4e5f51f6fef9d99e190d7f5e53354c94df469c207a19
sha512=8f6a3d370d6fc8f20aa8a69940de263eabdd16925dcde2125807863e1b66db79f5e7164f7116cc643149bac2481ea93744d53408213ddadd13e9c6c4d4eb2260
Description
Added to opam-repository:
README
reddit_api is a set OCaml client libraries for Reddit's API.
reddit_api_kernel provides:
- Types for representing Reddit's API parameters and responses
- Functions for building HTTP requests and handling the associated responses for Reddit's API endpoints.
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.
Documentation
Here. I recommend the Reddit_api_kernel.Endpoint and Reddit_api_async.Connection modules as entry points.
Example
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 ()Goals and non-goals
Goals
- Provide a typed interface to Reddit's API endpoints and responses.
Encode knowledge, documented or otherwise, about correct usage of the API via the type system.
- Don't raise exceptions if Reddit is behaving "as expected."
- Express corner cases in response types. For example, are there surprising cases where a field might not be present? Make the field optional instead of making each user discover this on their own.
- Handle common Reddit server issues such as 503 errors automatically, or else warn about them via the response type.
Provide workarounds when we get the above wrong:
- The ability to directly edit the HTTP requests generated for each endpoint.
- A
Connection.call_rawfunction that allows users to access HTTP responses directly.
Non-goals
Be perfect
- Reddit's API is not very well documented. Determining which inputs and outputs are legal is largely a matter of trial and error. At any given time, it's likely that we allow some invalid combination of inputs, or forbid a valid combination, or fail to handle some valid response.
Express "unexpected" Reddit behavior in the type system.
- If we get something from Reddit that we don't understand, we'll just raise. We don't make every function return a
(_, [`couldn't_parse_response]) Result.t).
- If we get something from Reddit that we don't understand, we'll just raise. We don't make every function return a
Credits
Thanks to PRAW for providing innumerable examples of Reddit API client code.
Dependencies (4)
-
ezjsonm
>= "1.2.0" -
core_kernel
>= "v0.14.0" & < "v0.16.0" -
cohttp
>= "5.0.0" -
dune
>= "2.8"
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by (1)
-
reddit_api_async
>= "0.2.1"
Conflicts
None
Build status
Results of building reddit_api_kernel with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.2.1 (this version) | good | good | n/a | n/a | n/a |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure