Blitline提供了从命令行调用的示例;如何将其转换为clojure?
$ curl "http://api.blitline.com/job" -d json='{ "src" : "http://www.google.com/logos/2011/yokoyama11-hp.jpg", "functions" : [ {"name": "blur", "params" : {"radius" : 0.0, "sigma" : 2.0}, "save" : { "image_identifier" : "some_id" }} ]}'发布于 2012-09-18 10:08:53
上面的答案是正确的。为了完整起见,我附上了您需要的完整代码:
(require '[clj-http.client :as http])
(require '[clojure.data.json :as json])
(def post
(http/post "http://api.blitline.com/job" {
:body
(json/json-str
{ "json"
{ "application_id" "sgOob0A3b3RdYaqwTEJCpA"
"src" "http://www.google.com/logos/2011/yokoyama11-hp.jpg"
"functions" [ {
"name" "blur"
"params" {
"radius" 0.0
"sigma" 2.0
}
"save" { "image_identifier" "some_id" }
}
]}})
:body-encoding "UTF-8"
:content-type :json
:accept :json
}))
(json/read-json (:body post))发布于 2012-09-15 19:00:00
您可以使用clj-http.client和clojure.data.json。下面是一些我用来与城市飞艇JSON API对话的示例代码:
(ns my-ns
(:require [clj-http.client :as http]
[clojure.data.json :as json]))
(def uu-base-url
"https://go.urbanairship.com")
(def auth ["secret" "password"])
(defn broadcast-message*
[auth text]
(http/post (str uu-base-url "/api/push/broadcast/") ;; target url
{:basic-auth auth ;; leave this out if you don't need HTTP basic authentication
:content-type "application/json"
:body (json/json-str
;; clojure data to be converted into JSON request body
{:aps {:badge 1
:alert text}})}))https://stackoverflow.com/questions/12433314
复制相似问题