Makes working with pagination APIs fast. Based on core.async.
Given a function that knows how to operate on a page in a pagination API, for example, the tMDB API:
(defn movies
([query page]
(-> (client/get (str api-endpoint "/search/movie") {:query-params {"api_key" api-key
"query" query
"page" page}
:as :json})
:body))
([query page c]
(client/get (str api-endpoint "/search/movie") {:query-params {"api_key" api-key
"query" query
"page" page}
:async? true
:as :json}
(fn [resp] (a/onto-chan c (:results (:body resp))))
(fn [e] (a/>!! c (.getMessage e))))))
You can then use the blat
library to retrieve all pages concurrently.
(require ' [blet.core :refer [fetch]])
(defn fetch-all [query]
(let [f (partial find query)
{results :results total :total_pages} (f 1)]
(fetch f 2 (inc total) results)))
Please refer to the miniseries available on Youtube, "Exploratory programming with the TMDb API".
Distributed under the Eclipse Public License (the same as Clojure) together with the 966.icu license.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close