<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged clj-http</title>
<link>https://ask.clojure.org/index.php/tag/clj-http</link>
<description></description>
<item>
<title>REST API response body is not a string?</title>
<link>https://ask.clojure.org/index.php/10217/rest-api-response-body-is-not-a-string</link>
<description>&lt;p&gt;It's been a while since I've written Clojure, so I am rusty.&lt;/p&gt;
&lt;p&gt;Basically, I'm trying to write code which does an HTTP GET on a REST API and converts that JSON array of objects into clojure data (list of Maps?). The JSON data looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[
    {
        &quot;id&quot;: 1,
        &quot;category&quot;: &quot;technical&quot;,
        &quot;asin&quot;: &quot;0131103628&quot;,
        &quot;title&quot;: &quot;C Programming Language, 2nd Edition&quot;,
        &quot;publication_date&quot;: &quot;1988-04-01T00:00:00Z&quot;,
        &quot;review&quot;: &quot;The C book.&quot;,
        &quot;created_at&quot;: &quot;2020-03-06T20:48:00Z&quot;
    },
    {
        &quot;id&quot;: 2,
        &quot;category&quot;: &quot;technical&quot;,
        &quot;asin&quot;: &quot;0387966080&quot;,
        &quot;title&quot;: &quot;The Science of Fractal Images&quot;,
        &quot;publication_date&quot;: &quot;1988-07-19T00:00:00Z&quot;,
        &quot;review&quot;: &quot;The book on fractal algorithms.  Sadly, no longer in print.  I had to search high and low for a used copied.&quot;,
        &quot;created_at&quot;: &quot;2020-03-06T20:48:00Z&quot;
    },
    // etc..
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I'm using &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/http-kit/http-kit&quot;&gt;http-kit&lt;/a&gt; (I've also tried &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/dakrone/clj-http&quot;&gt;clj-http&lt;/a&gt;) to call the REST API and return the body. Later, I try converting the body to Clojure data. I've tried using both &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/data.json&quot;&gt;org.clojure/data.json&lt;/a&gt; and &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/dakrone/cheshire&quot;&gt;cheshire&lt;/a&gt;.  However, I don't belive the data is being converted correctly.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn get-books-body
  []
  (:body @(client/get books-url api-options)))

(defn get-books
  []
  (parse-string get-books-body true))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I try to display the type of the body, it shows up as an address instead of a string:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure-json-test.core=&amp;gt; (type get-books-body)
clojure_json_test.core$get_books_body
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I cannot look at the first record, after converting from JSON:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure-json-test.core=&amp;gt; (first get-books)
Execution error (IllegalArgumentException) at clojure-json-test.core/eval3169 (form-      init15378865171954877190.clj:1).
Don't know how to create ISeq from: clojure_json_test.core$get_books
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any idea what I am doing wrong?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10217/rest-api-response-body-is-not-a-string</guid>
<pubDate>Sat, 20 Feb 2021 08:42:46 +0000</pubDate>
</item>
<item>
<title>Reading a JSON stream over HTTP, indefinitely?</title>
<link>https://ask.clojure.org/index.php/9128/reading-a-json-stream-over-http-indefinitely</link>
<description>&lt;p&gt;I am trying to read a &lt;code&gt;json&lt;/code&gt; HTTP stream and use the &lt;code&gt;json&lt;/code&gt; elements, indefinitely.&lt;/p&gt;
&lt;p&gt;I came up with this code below, but it does close the stream and only returns 30 results - how do I &lt;em&gt;indefinitely&lt;/em&gt; use the HTTP stream?&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns core
  (:require [clj-http.client :as http]
            [cheshire.core :as json]
            [clojure.java.io :as io]
            [clojure.core.async :as async]))

(def gh-url &quot;https://api.github.com/events&quot;)
(def chan (async/chan 100))

(async/go
  (loop [r (async/&amp;lt;! chan)]
    (when (not-empty r) (println (:type r)))
    (recur (async/&amp;lt;! chan))))

(defn read-gh-stream [url]
  (with-open [stream (-&amp;gt; url (http/get {:as :stream}) :body)]
    (let [lines (-&amp;gt; stream io/reader (json/parse-stream true))]
      (doseq [l lines]
        (async/go
          (async/&amp;gt;! chan l))))))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>IO</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9128/reading-a-json-stream-over-http-indefinitely</guid>
<pubDate>Sat, 29 Feb 2020 07:59:50 +0000</pubDate>
</item>
<item>
<title>How to do a HTTP request over a unix socket in Clojure</title>
<link>https://ask.clojure.org/index.php/8990/how-to-do-a-http-request-over-a-unix-socket-in-clojure</link>
<description>&lt;p&gt;I want to a HTTP request over a UNIX socket, like the following example using curl and docker:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ curl --unix-socket /var/run/docker.sock http://localhost/images/json
[
  {
    &quot;Containers&quot;: -1,
    &quot;Created&quot;: 1577395270,
    &quot;Id&quot;: &quot;sha256:ce6c1e7ac56533e2742030f033cf0d8cf0adc996c7bb87453eb5adc266b2ef2e&quot;,
    &quot;Labels&quot;: null,
    &quot;ParentId&quot;: &quot;&quot;,
    &quot;RepoDigests&quot;: [
      &quot;busybox@sha256:7fe0cb3632d9ea7b2a9ab4427e339e01f7cdfeff50674804cb8946664976c610&quot;
    ],
    &quot;RepoTags&quot;: [
      &quot;busybox:musl&quot;
    ],
    &quot;SharedSize&quot;: -1,
    &quot;Size&quot;: 1461385,
    &quot;VirtualSize&quot;: 1461385
  }
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As far as I've seen, clj-http doesn't seem to support this.&lt;/p&gt;
&lt;p&gt;What would be a recommended/idiomatic way of doing this in Clojure?&lt;/p&gt;
</description>
<category>Libs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8990/how-to-do-a-http-request-over-a-unix-socket-in-clojure</guid>
<pubDate>Sat, 04 Jan 2020 15:08:16 +0000</pubDate>
</item>
</channel>
</rss>