【问题标题】:Interacting with a REST API from Clojure与 Clojure 中的 REST API 交互
【发布时间】:2012-10-14 22:46:54
【问题描述】:

在无需运行 Web 服务器的情况下,向外部 REST API 发送和接收请求的建议方法是什么?我似乎找不到任何关于发出请求和解析结果 JSON 的信息。到目前为止我唯一发现的只是 json 解析的东西(使用 Cheshire 库)。

任何帮助将不胜感激!

【问题讨论】:

    标签: api rest clojure request


    【解决方案1】:

    一个与外部 REST API 交互的好库是clj-http,它使用Apache HTTPClient)。对于 JSON,有几个选项:clojure.data.json(核心库)和cheshire 是一些流行的选项。 lib clj-http 将 cheshire 作为依赖项,并支持 JSON。Cheshire 使用 Jackson

    例如,使用clj-http:

    (ns my.core
      (:require [clj-http.client :as client]))
    
    (client/put my-url
      {:form-params body
       :content-type :json
       :oauth-token @token
       :throw-exceptions false
       :as :json})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多