(ns metabase.util.http
  (:require
   [clj-http.client :as http]
   [medley.core :as m]
   [metabase.util.json :as json]))
(defn- parse-http-headers [headers]
  (json/decode headers))

Fetches url and parses body as json, returning it.

(defn ^:dynamic *fetch-as-json*
  [url headers]
  (let [headers (cond-> headers
                  (string? headers) parse-http-headers)
        response (http/get url (m/assoc-some {:as :json} :headers headers))]
    (:body response)))