Clojure服务之间的通信

时间:2020-04-13 18:16:50

标签: clojure microservices

我需要放置一个Clojure服务,以通过HTTP调用与另一个服务进行通信,在Java中,我们可以使用RestTemplate做类似的事情:

             ResponseEntity<Product[]> responseEntity = new RestTemplate().getForEntity(
                    "http://localhost:8001/products/store/all", Product[].class);

Clojure用此代码完成相同工作的相似方式是什么?

1 个答案:

答案 0 :(得分:2)

您可以使用clj-http和任何cheshire之类的JSON解析器:

(ns example
  (:require [clj-http.client :as client]
            [cheshire.core :as :json]))

(def products
   (-> (client/get "http://localhost:8001/products/store/all") 
       (json/parse-string true)))