gpt4 book ai didi

clojure - 如何在 Compojure 中设置状态码?

转载 作者:行者123 更新时间:2023-12-01 07:56:48 25 4
gpt4 key购买 nike

我正在用 Clojure 和 Compojure 编写一个小网站。我想根据找到或未找到的数据为每个请求设置 HTTP 响应状态。

最后一个调用是 html5 宏,它将需要发送回浏览器的 html 返回给处理程序。是否可以在这里以某种方式设置 HTTP 响应状态?

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

(defn layout [title & content]
(html5
(head title)
(body content)))

最佳答案

如果您只返回文本,该文本将是响应的正文。如果您返回一个 map ,该 map 可以描述响应的其他方面。

(defn layout [title & content]
{:status 200
:body (html5 (head title) (body content))})

关于clojure - 如何在 Compojure 中设置状态码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22798004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com