       (assoc :status :failed)))
 
 ;; TODO only implementing JSON/RAW format and not implementing prefixes for now since we don't anything else
-(defn ajax [method url message channel & {:keys [params keywords? context headers format]
-                                          :or {keywords? true format :json}}]
+(defn ajax [method url message channel & {:keys [params keywords? context headers format body]
+                                          :or {keywords? true format :edn}}]
   (let [uuid frontend.async/*uuid*
-        common-opts {:finally #(binding [frontend.async/*uuid* uuid]
-                                 (put! channel [message :finished context]))}
         format-opts (case format
                       :json {:format (merge (clj-ajax/json-request-format)
                                             (json-response-format {:keywords? keywords? :url url :method method}))

                                               {:X-CSRFToken (utils/csrf-token)})
                                             headers)
                             :handler #(binding [frontend.async/*uuid* uuid]
                                         (put! channel [message :success (assoc % :context context :scopes (scopes-from-response %))]))
                             :error-handler #(binding [frontend.async/*uuid* uuid]
                                       (put! channel [message :failed (normalize-error-response % {:url url :context context})]))}
                      ;; TODO: use a custom reader or similar for raw to handle more like json
                      :raw {:format (clj-ajax/raw-format)
                            :handler #(binding [frontend.async/*uuid* uuid]
                                        (put! channel [message :success {:resp % :context context}]))
                            :error-handler #(binding [frontend.async/*uuid* uuid]
                                       (put! channel [message :failed {:resp % :url url :context context :status :failed}]))})
        opts (merge common-opts format-opts)]
    (put! channel [message :started context])
    (clj-ajax/ajax-request url method
                           (clj-ajax/transform-opts opts))))

;; This is all very mess, it should be cleaned up at some point
(defn managed-ajax [method url & {:keys [params keywords? headers format response-format]

   :content-type "application/xml"
   :write identity})

(defn normalize-error-response [default-response props]
  (-> default-response
      (merge props)
