Clojure服务之间的通信

问题描述 投票:0回答:1

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

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

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

clojure microservices
1个回答
1
投票

您可以使用clj-http和任何JSON解析器,例如cheshire

(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)))
© www.soinside.com 2019 - 2024. All rights reserved.