【问题标题】:What is the difference between body and body-params in compojure-api?compojure-api 中的 body 和 body-params 有什么区别?
【发布时间】:2015-10-24 08:31:00
【问题描述】:

在 compojure-api 中,我注意到这两种指定资源 API 的方式:

(POST* "/register" []
    :body [user UserRegistration]
    (ok)))

(POST* "/register" []
    :body-params [username :- String,
                  password :- String]
    (ok)))

这两者有什么区别?使用一个与另一个有什么影响?

【问题讨论】:

    标签: clojure swagger plumatic-schema compojure-api


    【解决方案1】:

    唯一的区别在于参数的指定方式(以及之后的解构方式):

    body:

    将正文参数读入增强的let。第一个参数是let 符号,第二个是 coerced! 反对的 Schema。

    示例: :body [user User]

    body-params:

    使用管道letk 表示法重组 body-params。

    示例::body-params [id :- Long name :- String]

    根据情况,您可能更喜欢其中一种。在这两种情况下,参数(user 在第一种情况下,idname 在第二种情况下)都将在正文的范围内。

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 2011-09-12
      • 2017-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多