Search code examples
clojuremicroservices

Communication between Clojure services


I need to put a Clojure service to communicate with another through HTTP calls, in java we can do something like that using RestTemplate like this:

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

What would be the similar way in Clojure to do the same job with this code?


Solution

  • You can use clj-http and any JSON parser like 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)))