This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-26
Channels
- # announcements (2)
- # asami (2)
- # aws (34)
- # babashka (6)
- # beginners (9)
- # calva (76)
- # chlorine-clover (10)
- # circleci (5)
- # clj-kondo (2)
- # clojure (40)
- # clojure-australia (3)
- # clojure-europe (15)
- # clojurescript (39)
- # conjure (1)
- # core-async (4)
- # cursive (4)
- # datahike (1)
- # datomic (69)
- # figwheel-main (1)
- # graalvm (16)
- # honeysql (9)
- # hyperfiddle (2)
- # jobs-discuss (2)
- # lsp (36)
- # luminus (1)
- # malli (11)
- # off-topic (13)
- # pathom (1)
- # portal (1)
- # portkey (3)
- # reitit (25)
- # reveal (1)
- # rewrite-clj (5)
- # spacemacs (2)
- # sql (4)
- # vrac (90)
Hi, is there a way to automatically format transit? Using this fresh install
(defn service-routes []
["/api"
{:coercion spec-coercion/coercion
:muuntaja formats/instance
:swagger {:id ::api}
:middleware [;; query-params & form-params
parameters/parameters-middleware
;; content-negotiation
muuntaja/format-negotiate-middleware
;; encoding response body
muuntaja/format-response-middleware
;; exception handling
coercion/coerce-exceptions-middleware
;; decoding request body
muuntaja/format-request-middleware
;; coercing response bodys
coercion/coerce-response-middleware
;; coercing request parameters
coercion/coerce-request-middleware
;; multipart
multipart/multipart-middleware]}
If I send a request to math/plus
with a transit payload, I get a spec error. The body does not seem to be parsed. Any ideas?
["/plus"
{:get {:summary "plus with spec query parameters"
:parameters {:query {:x int?, :y int?}}
:responses {200 {:body {:total pos-int?}}}
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200
:body {:total (+ x y)}})}
:post {:summary "plus with spec body parameters"
:parameters {:body {:x int?, :y int?}}
:responses {200 {:body {:total pos-int?}}}
:handler (fn [{{{:keys [x y]} :body} :parameters}]
{:status 200
:body {:total (+ x y)}})}}]]
@UP82LQR9N I didn’t even try the get method. Are you able to use the post request? That’s where I’m stuck. Thank you
$ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"x": 1,"y": 3}' ''
{"total":4}
$
@UP82LQR9N - yeah json works fine, it’s only the transit encoding I’m having an issue with
When I post via postman the transit payload doesn’t seem to parse and then it causes spec errors
(POST "/api/plus" {:headers {"Accept" "Application/Transit+Json" "Content-Type" "Application/Transit+Json"} :params {:x 4 :y 6} :handler println :error-handler println})
params vs body did you mean like params in path vs params in body? the screenshot shows it's in the body by POST
@UP82LQR9N - Thank you. This was my exact request just using :body as the key instead of :params.
(POST " " {:headers {"Accept" "Application/Transit+Json"}
:body {:quantity 2.9, :uuid "test uuid"}
:handler tap>})
@UP82LQR9N thanks for taking the time on this silliness