add basic support for operations to specify whether the 'Location' response header should be followed or not (if it is present in the response of course)
This commit is contained in:
parent
2ed10827d3
commit
ad44c28666
|
@ -9,20 +9,23 @@
|
||||||
(defn- ->fhir-resource-name [x]
|
(defn- ->fhir-resource-name [x]
|
||||||
(name (->CamelCase x)))
|
(name (->CamelCase x)))
|
||||||
|
|
||||||
(defn- fhir-request [type base-url resource-url & {:keys [params body]}]
|
(defn- fhir-request [type base-url resource-url & {:keys [params body follow-location?]}]
|
||||||
(let [query (map->query-string params)
|
(let [query (map->query-string params)
|
||||||
url (build-url base-url resource-url query)]
|
url (build-url base-url resource-url query)
|
||||||
|
follow-location? (if (nil? follow-location?) true follow-location?)]
|
||||||
(try
|
(try
|
||||||
(let [response (case type
|
(let [response (case type
|
||||||
:get (http-get-json url)
|
:get (http-get-json url)
|
||||||
:post (http-post-json url body)
|
:post (http-post-json url body)
|
||||||
:put (http-put-json url body)
|
:put (http-put-json url body)
|
||||||
:delete (http-delete-json url body))]
|
:delete (http-delete-json url body))
|
||||||
(-> (if-let [location (get-in response [:headers "Location"])]
|
location (get-in response [:headers "Location"])]
|
||||||
(http-get-json location)
|
(if location
|
||||||
response)
|
(if follow-location?
|
||||||
:body
|
(-> (http-get-json location)
|
||||||
(json/parse-string true)))
|
:body
|
||||||
|
(json/parse-string true))
|
||||||
|
location)))
|
||||||
(catch ExceptionInfo ex
|
(catch ExceptionInfo ex
|
||||||
(let [{:keys [status body headers]} (:object (ex-data ex))
|
(let [{:keys [status body headers]} (:object (ex-data ex))
|
||||||
fhir-resource-response? (.contains (get headers "Content-Type") "application/json+fhir")]
|
fhir-resource-response? (.contains (get headers "Content-Type") "application/json+fhir")]
|
||||||
|
|
Reference in a new issue