Liking cljdoc? Tell your friends :D

Table of Contents

  1. Definition
  2. Installation
  3. Usage example
  4. Video tutorial
  5. License

Definition

Makes working with pagination APIs fast. Based on core.async.

Installation

img

Usage example

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)))

Video tutorial

Please refer to the miniseries available on Youtube, "Exploratory programming with the TMDb API".

License

Distributed under the Eclipse Public License (the same as Clojure) together with the 966.icu license.

img

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close