···11+ISC License
22+33+Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>
44+55+Permission to use, copy, modify, and distribute this software for any
66+purpose with or without fee is hereby granted, provided that the above
77+copyright notice and this permission notice appear in all copies.
88+99+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1010+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1111+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1212+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1313+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1414+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1515+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+56-36
README.md
···11# OCaml Karakeep API Client
2233-This library provides OCaml bindings to the Karakeep API for bookmark management.
33+An OCaml client library for the [Karakeep](https://karakeep.app) bookmark service API.
44+Built on [Eio](https://github.com/ocaml-multicore/eio) for structured concurrency with
55+a type-safe interface using [jsont](https://erratique.ch/software/jsont) for JSON encoding/decoding.
4657## Features
6877-- Fetch bookmarks from Karakeep instances with pagination
88-- Retrieve detailed bookmark information
99-- Create new bookmarks
1010-- Access and download bookmark assets
1111-- Filter bookmarks by tags
99+- Full API coverage for bookmarks, tags, lists, highlights, and user operations
1010+- Automatic pagination support
1111+- Type-safe JSON encoding/decoding with jsont
1212+- Built on Eio for structured concurrency
1313+- Cmdliner integration for CLI tools
12141315## Installation
1414-1515-To install the library, you can use opam:
16161717```bash
1818opam install karakeep
···2121Or pin the development version:
22222323```bash
2424-opam pin add karakeep.dev git+https://github.com/yourusername/ocaml-karakeep.git
2424+opam pin add karakeep.dev git+https://tangled.org/@anil.recoil.org/ocaml-karakeep.git
2525```
26262727## Configuration
28282929-The library requires an API key for authentication. You can obtain an API key from your Karakeep instance.
2929+The library requires an API key for authentication. You can obtain an API key from your Karakeep instance settings.
30303131## Usage Example
32323333```ocaml
3434-open Lwt.Infix
3535-open Karakeep
3434+let () =
3535+ Eio_main.run @@ fun env ->
3636+ Eio.Switch.run @@ fun sw ->
36373737-(* Setup the Karakeep client *)
3838-let api_key = "your_api_key"
3939-let base_url = "https://hoard.recoil.org"
3838+ (* Create the client *)
3939+ let client =
4040+ Karakeep.create ~sw ~env
4141+ ~base_url:"https://hoard.recoil.org"
4242+ ~api_key:"your_api_key"
4343+ in
40444141-(* Fetch recent bookmarks *)
4242-let fetch_recent_bookmarks () =
4343- fetch_bookmarks ~api_key ~limit:10 base_url >>= fun response ->
4444-4545- (* Process bookmarks *)
4545+ (* Fetch recent bookmarks *)
4646+ let result = Karakeep.fetch_bookmarks client ~limit:10 () in
4647 List.iter (fun bookmark ->
4747- let title = match bookmark.title with
4848- | Some t -> t
4949- | None -> "(No title)"
5050- in
5151- Printf.printf "- %s\n URL: %s\n\n" title bookmark.url
5252- ) response.data;
5353-5454- Lwt.return_unit
4848+ let title = Karakeep.bookmark_title bookmark in
4949+ Printf.printf "- %s\n" title
5050+ ) result.bookmarks;
5151+5252+ (* Fetch all bookmarks (handles pagination automatically) *)
5353+ let all_bookmarks = Karakeep.fetch_all_bookmarks client () in
5454+ Printf.printf "Total bookmarks: %d\n" (List.length all_bookmarks);
5555+5656+ (* Create a new bookmark *)
5757+ let _new_bookmark =
5858+ Karakeep.create_bookmark client
5959+ ~url:"https://ocaml.org"
6060+ ~title:"OCaml Programming Language"
6161+ ~tags:["programming"; "ocaml"]
6262+ ()
6363+ in
55645656-(* Run the function *)
5757-let () = Lwt_main.run (fetch_recent_bookmarks ())
6565+ (* Search bookmarks *)
6666+ let search_results = Karakeep.search_bookmarks client ~query:"ocaml" () in
6767+ Printf.printf "Found %d results\n" (List.length search_results.bookmarks)
6868+```
6969+7070+## Error Handling
7171+7272+All operations may raise `Eio.Io` exceptions with a `Karakeep.E` error payload:
7373+7474+```ocaml
7575+try
7676+ let bookmarks = Karakeep.fetch_bookmarks client () in
7777+ (* ... *)
7878+with
7979+| Eio.Io (Karakeep.E err, _) ->
8080+ Printf.eprintf "Karakeep error: %s\n" (Karakeep.error_to_string err)
5881```
59826083## Documentation
61846262-See the [documentation](doc/index.md) for more detailed usage instructions and API reference.
8585+- [API Documentation](doc/index.md)
8686+- Online documentation is generated with `dune build @doc`
63876488## License
65896666-This library is licensed under the ISC license.
6767-6868-## Contact
6969-7070-For issues and questions, please create an issue on the GitHub repository.9090+ISC License. See [LICENSE.md](LICENSE.md) for details.
+5
dune
···11+; Root dune file
22+33+; Ignore directories that shouldn't be processed by dune
44+55+(data_only_dirs karakeep-src third_party)
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+16(** Karakeep CLI support library
2738 This module provides cmdliner terms and utilities for building command-line
+5
lib/karakeep.ml
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+16(** Karakeep API client implementation *)
2738include Karakeep_proto
+5
lib/karakeep.mli
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+16(** Karakeep API client
2738 This module provides a client for interacting with the Karakeep bookmark
+5
lib/proto/karakeep_proto.ml
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+16(** Karakeep API protocol types and JSON codecs *)
2738(** {1 Helper Codecs} *)
+5
lib/proto/karakeep_proto.mli
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+16(** Karakeep API protocol types and JSON codecs
2738 This module provides type definitions and jsont codecs for the Karakeep