clojure - 使用 clojure 从 api 获取数据并记录结果
问题描述
我对 clojure 很陌生,我熟悉 java 和 PHP。我已经分配了新的 clojure 作业来从外部 API 获取数据并执行一些过程。
这是我的 API 请求,我使用 curl 命令进行了尝试
curl -i -X POST -H "Content-Type: application/json" -d "{\"uid\":\"uId\", \"param\":\"1\"}" http://localhost:8081/api/getData
结果是 - {"comp":true,"yUi":"78.2555","xUi":"4.5233","id":"10"}
我已经使用 clojure 应用了上述过程,我需要记录这些返回值。你能帮我用 clojure 来做吗
这就是我尝试的方式
(defn- get-data
"api call"
[uId]
(try
(log/info (trs "start process: {0}" (str "uid" uId )))
(when-let [ui (client/post "http://localhost:8081/api/getData" {:form-params {:uid uId,:param "1"} :content-type :json })]
(log/info (trs "get data: {0} {1} {2} {3}" (:comp ui) (:yUi ui) (:xUi ui) (:id ui))))
(catch Throwable e
(log/error "api call failed:" (.getMessage e)))))
解决方案
推荐阅读
- ios - UIImagePicker 更改搜索栏占位符文本的颜色
- r - 将每个值分配给没有循环的单独列表元素
- pip-tools - 解析 base.py 时 pip-compile 失败
- python - 再说一遍:请求库中的“JSON 对象必须是 str、bytes 或 bytearray,而不是 list”
- bash - 使用数组键的名称保存文件
- java - 将 Spire.Doc.jar 用于 docx 文件时,Netbeans 中的包中缺少类
- go - 使用 dgrijalva/jwt-go 包生成 jwt 令牌 RS256 的问题
- node.js - 无法使用 cloudinary 上传图片
- python-3.x - 使用 Pyinstaller 制作 .exe 的问题:编译完成但 .exe 失败
- ios - iOS中macOS popUpButton的替代品?