biff
biff copied to clipboard
Have starter app include example of returning html with full response map
See this comment: https://github.com/jacobobryant/biffweb.com/pull/4#issuecomment-2307718376
Something like this? Happy to open up a PR.
diff --git a/starter/src/com/example/app.clj b/starter/src/com/example/app.clj
index 265dab1..4b37244 100644
--- a/starter/src/com/example/app.clj
+++ b/starter/src/com/example/app.clj
@@ -142,6 +142,21 @@
:headers {"content-type" "application/json"}
:body params})
+(defn custom-response
+ "Any biff handler that returns a vector is
+ automatically converted into html (see source
+ for com.biffweb.impl.middleware/wrap-render-rum).
+ If you need to escape this behavior, return
+ a ring response map instead."
+ [_ctx]
+ {:status 200
+ :headers {"content-type" "text/html"}
+ :cookies {"foo" {:value "bar"
+ :max-age (* 365 86400)}}
+ :body (rum/render-static-markup
+ [:code "Open your browser console to view
+ the custom headers set by biff."])})
+
(def module
{:static {"/about/" about-page}
:routes ["/app" {:middleware [mid/wrap-signed-in]}
@@ -149,5 +164,6 @@
["/set-foo" {:post set-foo}]
["/set-bar" {:post set-bar}]
["/chat" {:get ws-handler}]]
- :api-routes [["/api/echo" {:post echo}]]
+ :api-routes [["/api/echo" {:post echo}]
+ ["/api/custom-response" {:get custom-response}]]
:on-tx notify-clients})
Yep, like that. No need for a PR--I still need to decide whether this should be an additional route, or if I should just add some comments to the existing echo handler which already returns a map...