Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the status code in Compojure?

I am writing a small website in Clojure and Compojure. I would like to set the HTTP response status for each request based on the data found or not found.

The last call is the html5 macro that returns to the handler the html that needs to be sent back to the browser. Is it possible to set the HTTP response status somehow here?

(ns myapp.views.layout
  (:require
    [hiccup.page :refer (html5 include-css include-js)]))

(defn layout [title & content]
  (html5
    (head title)
    (body content)))
like image 507
Istvan Avatar asked Dec 03 '25 10:12

Istvan


1 Answers

If you only return text that text will be the body of the response. If you return a map, the map can describe other aspects of the response.

(defn layout [title & content]
  {:status 200
   :body (html5 (head title) (body content))})
like image 71
noisesmith Avatar answered Dec 06 '25 10:12

noisesmith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!