Creating the API
As the first step, let’s see how we can connect to the REST API provided by the Cat API site and extract the content that we need.
Parsing Cat Picture Links
In order to fetch our links, we need to create an HTTP client. Let’s use the excellent clj-http library for this task.[60] As always, we start by adding the dependency to our project.clj file.
| :dependencies [... [clj-http "2.0.0"]] |
Note that if your application is running, you need to restart it in order for the library to become available.
With the library in place, we can navigate to the swagger-service.routes.services namespace and add the code for reading the links. Let’s first reference it in our namespace as client.
| (:require ... |
| [clj-http.client :as client]) ... |
Get Web Development with Clojure, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.