We will be using HttpKit to access the GitHub API and pull down information about an organization’s repositories. We will then leverage Clojure’s built in features to manipulate and explore the collection. For now, we won’t attempt anything asynchronous or complicated — we can leave that for a future post :)
In some new directory, I created a deps.edn
file with the following dependencies:
{:deps
{http-kit {:mvn/version "2.5.0"}
org.clojure/data.json {:mvn/version "1.0.0"}
org.clojure/core.async {:mvn/version "1.3.610"}}}
Then we can fire up a clj
REPL in the same directory as the deps.edn
file:
❯ clj
Clojure 1.10.1
user=>
And require (paste in) our dependencies in the REPL:
(require '[org.httpkit.client :as http])
(require '[clojure.data.json :as json])
(require '[clojure.string :as str])
Keys in maps are also functions, which allows us to access key-values from a map very succinctly. Say we define a map called test-map
with :error
and :status
properties. We could access the property :status
like so:
(def test-map {:error nil :status 200}) ;=> #'user/test-map
(get test-map :status) ;=> 200
#programming #functional-programming #api #clojure