如何设置Compojure中的状态代码? [英] How to set the status code in Compojure?

查看:112
本文介绍了如何设置Compojure中的状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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)))


推荐答案

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

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))})

这篇关于如何设置Compojure中的状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆