【发布时间】:2016-10-02 16:00:15
【问题描述】:
我将 liberator 用于 REST 服务,我的内容类型是 json。
当:authorized?(或其他决定)失败时,它会返回我不想要的text/html。
我需要 liberator 为所有类型的错误返回 json 数据格式。
【问题讨论】:
标签: clojure functional-programming clojurescript compojure liberator
我将 liberator 用于 REST 服务,我的内容类型是 json。
当:authorized?(或其他决定)失败时,它会返回我不想要的text/html。
我需要 liberator 为所有类型的错误返回 json 数据格式。
【问题讨论】:
标签: clojure functional-programming clojurescript compojure liberator
Handlers 可用于自定义在不同情况下执行的操作,例如处理正常、未找到资源或未通过身份验证。例如:
(resource
:available-media-types ["application/json"]
:authorized? (fn [ctx] ...)
:handle-unauthorized {:message "You need to be authenticated"}
:exists? (fn [ctx] ...)
:handle-not-found {:message "Resource not found"})
在其他情况下,处理程序可以是一个常量值或将产生它的函数。
【讨论】: