This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-19
Channels
- # admin-announcements (1)
- # asami (9)
- # aws (46)
- # beginners (117)
- # calva (9)
- # cider (48)
- # clj-kondo (27)
- # cljdoc (6)
- # clojure (41)
- # clojure-australia (2)
- # clojure-europe (22)
- # clojure-nl (3)
- # clojure-spec (3)
- # clojure-uk (26)
- # clojurescript (57)
- # code-reviews (25)
- # cursive (9)
- # data-science (2)
- # datomic (31)
- # events (1)
- # expound (24)
- # figwheel-main (8)
- # fulcro (38)
- # graalvm (40)
- # helix (6)
- # jackdaw (4)
- # java (5)
- # jobs (1)
- # kaocha (7)
- # kekkonen (1)
- # meander (65)
- # off-topic (67)
- # pathom (4)
- # reagent (9)
- # reitit (8)
- # remote-jobs (3)
- # ring (2)
- # shadow-cljs (24)
- # spacemacs (13)
- # timbre (2)
- # tools-deps (4)
I have an API that uses Reitit and Swagger, with one of the routes being POST /book
. The book object has a name, id, currency. When I use swagger to hit this end point, it works fine. But when I try to hit it with and http-kit/client
POST, it gives me a coercion error. I think it has something to do with the request being turned into a Bytestream at some point, but if I put a slurp in my handler, presumably the swagger request will break (since presumably it's not a bytestream). What am I doing wrong here?
This is the post request:
@(http/post ""
{:body {:name "Jim LLC"
:id "021b148b-8d6a-425a-8cdb-9efad87b0d0d"
:currency :USD}})
This is the route, router config and handler
["/book" {:swagger {:tags ["Book"]}}
["" {:post {:handler create-book
:parameters {:body {:name string?
:id uuid?
:currency string?}}}}]]
(def router-config
{:data {:coercion coercion-spec/coercion
:muuntaja m/instance
:middleware [swagger/swagger-feature
muuntaja/format-middleware
coercion/coerce-request-middleware]}})
(defn create-book [req]
(tap> req)
(-> req
:body-params
(qualify "book")
(app/create-book!)
(rr/response)))
And the (partial) response to the post is...try setting the Content-Type
header in request and format the body into a JSON String.
if no content-type is set in the request, the server doesn’t parse it and nothing get’s copied into parsed :value