Fork me on GitHub
#re-frame
<
2022-11-28
>
kokonut14:11:44

Hi, I am re-frame noob and wondering how to make a request to the backend with body part. Using this example from https://github.com/day8/re-frame-http-fx

(re-frame/reg-event-fx
  ::http-post
  (fn [_world [_ val]]
    {:http-xhrio {:method          :post
                  :uri             ""
                  :params          data
                  :timeout         5000
                  :format          (ajax/json-request-format)
                  :response-format (ajax/json-response-format {:keywords? true})
                  :on-success      [::success-post-result]
                  :on-failure      [::failure-post-result]}}))
When the backend expects a clojure map for the body, can I pass it here in data at params field? Or maybe somewhere else.

Ferdinand Beyer14:11:33

The :params will be sent according to the :method and :format. In your example, data will be JSON-encoded and send as the body of the POST request.

💯 1
Ferdinand Beyer14:11:06

> When the backend expects a clojure map for the body Does that mean that the backend expects the body in EDN format?

kokonut14:11:36

Oops, you are right. Actually the backend expects json not Clojure map.

👍 1