How do you send api-key as authorization with http-kit in Clojure?

319 views Asked by At

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.

I know the following would be the way to go in case of basic-auth:

{:url "<api-url>"
 :method :post
 :headers {"Content-Type" "application/json"}
 :basic-auth [<username> <password>]
 :body <body>)}

But a similar variation isn't working with api-key version. So far, I have tried:

{:basic-auth [<api-key> <api-value>]}
{:query-params {<api-key> <api-value>}}
{:query-params {:key <api-key>, :value <api-value>}}
{:headers {"Content-Type" "application/json"
           <api-key> <api-value>}
{:api-key [<api-key> <api-value>]}
{:api-key {<api-key> <api-value>}

and other variations, but it doesn't seem to be working.

(Note: 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.)

1

There are 1 answers

1
Denis Fuenzalida On

If you submit a POST request in Postman with the API Key auth to a non-existent endpoint, the request will fail but you can still inspect the headers that were attempted in the request using the Console. I used placeholder values and the request headers looks like this:

MYAPIKEY: MYAPIVALUE
Content-Type: application/json
User-Agent: PostmanRuntime/7.26.10
Accept: */*
Postman-Token: 0494818d-5401-4baa-8ef7-bfce46c7196e
Host: localhost:5001
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

This makes me think that with your request in http-kit needs at least a few of those headers (typically you'll need at least Content-type, Accept and your custom API key/value pair).