<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged http-kit</title>
<link>https://ask.clojure.org/index.php/tag/http-kit</link>
<description></description>
<item>
<title>http-kit authorization with api-key</title>
<link>https://ask.clojure.org/index.php/10411/http-kit-authorization-with-api-key</link>
<description>&lt;p&gt;I need to make an API call with  &lt;code&gt;http-kit&lt;/code&gt;  in Clojure where it uses &lt;code&gt;API-Key&lt;/code&gt; as authorization. That is, in Postman, you would usually have the option to add an &lt;code&gt;api-key&lt;/code&gt;, &lt;code&gt;api-value&lt;/code&gt; and the option to add it to &lt;code&gt;header&lt;/code&gt; or &lt;code&gt;query-params&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I know the following would be the way to go in case of basic-auth:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:url &quot;&amp;lt;api-url&amp;gt;&quot;
 :method :post
 :headers {&quot;Content-Type&quot; &quot;application/json&quot;}
 :basic-auth [&amp;lt;username&amp;gt; &amp;lt;password&amp;gt;]
 :body &amp;lt;body&amp;gt;)}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I need to make an API call with http-kit in Clojure where it uses API-Key as authorization. That is, in Postman, you would usually have the option to add an api-key, api-value and the option to add it to header or query-params.&lt;/p&gt;
&lt;p&gt;I know the following would be the way to go in case of basic-auth:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;{:url &quot;&amp;lt;api-url&amp;gt;&quot;
 :method :post
 :headers {&quot;Content-Type&quot; &quot;application/json&quot;}
 :basic-auth [&amp;lt;username&amp;gt; &amp;lt;password&amp;gt;]
 :body &amp;lt;body&amp;gt;)}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;But a similar variation isn't working with api-key version. So far, I have tried:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:basic-auth [&amp;lt;api-key&amp;gt; &amp;lt;api-value&amp;gt;]}

{:query-params {&amp;lt;api-key&amp;gt; &amp;lt;api-value&amp;gt;}}

{:query-params {:key &amp;lt;api-key&amp;gt;, :value &amp;lt;api-value&amp;gt;}}

{:headers {&quot;Content-Type&quot; &quot;application/json&quot;, 
                    &amp;lt;api-key&amp;gt; &amp;lt;api-value&amp;gt;}

{:api-key [&amp;lt;api-key&amp;gt; &amp;lt;api-value&amp;gt;]}

{:api-key {&amp;lt;api-key&amp;gt; &amp;lt;api-value&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and other variations, but it doesn't seem to be working.&lt;/p&gt;
&lt;p&gt;Note: &lt;br&gt;
- The authorization works on postman but I couldn't test the full api call there because the body is too long and too complex to copy, and the authorization isn't working from the application.&lt;br&gt;
- I keep getting a 401 error with all these different combinations, and some give typeerrors depending on where in the request they're placed. &lt;br&gt;
- The documentation isn't really useful. &lt;a rel=&quot;nofollow&quot; href=&quot;https://documenter.getpostman.com/view/9780542/TVmHDetH#e4296d1e-58f4-4f6d-873f-04fd8a69c872&quot;&gt;Here&lt;/a&gt; is the link. &lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10411/http-kit-authorization-with-api-key</guid>
<pubDate>Wed, 07 Apr 2021 11:07:39 +0000</pubDate>
</item>
<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>
</channel>
</rss>