如何使用包含 api 键的 clj-http 执行 http 请求?

How to perform an http request with clj-http including an api key?

我正在尝试向 api 发出一个 http 请求,将给定的句子更改为 yoda 可能说的方式。这是我的代码,当前出现包含 "Missing Mashape application key.":

的错误
(ns clojure-noob.core
  (:gen-class)
  (:require [clj-http.client :as client]))

(defn api-request [method path body]
  (:body
    (client/request
      {:basic-auth "*MY-AUTH-KEY-HERE*"
       :method method
       :url (str "https://yoda.p.mashape.com" path)
       :content-type "text/plain"
       :body body})))

(api-request :get "/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.++Oh+wait." "")

:basic-auth 部分是这段代码中最有问题的部分。 api 说明位于此处:https://market.mashape.com/ismaelc/yoda-speak 这是此 api 的有效 curl 请求的样子:

curl --get --include 'https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.++Oh+wait.' \
  -H 'X-Mashape-Key: *MY-AUTH-KEY-HERE*' \
  -H 'Accept: text/plain'

任何帮助都可能为我节省无数小时 scraping google 以获取有关如何完成此操作的线索。

看起来密钥需要进入一个名为 X-Mashape-Key 的特定 header 而不是使用 HTTP 基本身份验证。

(client/request
  {:headers {"X-Mashape-Key" "*MY-AUTH-KEY-HERE*"}
   :method method
   :url (str "https://yoda.p.mashape.com" path)
   :content-type "text/plain"
   :body body})))