Skip to content

Commit c6d5974

Browse files
Merge pull request #22 from parenthesin/feat/improve-flow-request
feat: improves flow request fn to work with x-www-form-urlencoded
2 parents 6708ad1 + d3c460a commit c6d5974

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

deps.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
metosin/reitit-pedestal {:mvn/version "0.7.2"}
1717
metosin/reitit-swagger {:mvn/version "0.7.2"}
1818
metosin/reitit-swagger-ui {:mvn/version "0.7.2"}
19+
ring/ring-codec {:mvn/version "1.2.0"}
1920
migratus/migratus {:mvn/version "1.6.3"}
2021
org.slf4j/slf4j-simple {:mvn/version "2.0.17"}
2122
prismatic/schema {:mvn/version "1.4.1"}}

src/parenthesin/helpers/state_flow/server/pedestal.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
(:require [cheshire.core :as json]
33
[clojure.string :as string]
44
[io.pedestal.test :as pt]
5+
[ring.util.codec :as codec]
56
[state-flow.api :as state-flow.api]
67
[state-flow.core :as state-flow :refer [flow]]))
78

89
(defn- do-request [service-fn verb route body headers]
910
(let [headers-with-default (merge {"Content-Type" "application/json"} headers)
10-
encoded-body (json/encode body)]
11+
content-type (get headers-with-default "Content-Type")
12+
encoded-body (case content-type
13+
"application/json" (json/encode body)
14+
"application/x-www-form-urlencoded" (codec/form-encode body)
15+
body)]
1116
(pt/response-for service-fn verb route :headers headers-with-default :body encoded-body)))
1217

1318
(defn- parsed-response
@@ -17,6 +22,9 @@
1722
request))
1823

1924
(defn request!
25+
"Flow that make http request using `:io.pedestal.http/service-fn`, not a fully
26+
featured http client, currently only supports content type `application/json`
27+
and `application/x-www-form-urlencoded`."
2028
[{:keys [method uri body headers]}]
2129
(flow "makes http request"
2230
[service-fn (state-flow.api/get-state (comp :io.pedestal.http/service-fn :webserver :webserver))]

0 commit comments

Comments
 (0)