compojure-api 中的 body 和 body-params 有什么区别?
What is the difference between body and body-params in compojure-api?
在 compojure-api 中,我注意到这两种指定资源 API 的方法:
(POST* "/register" []
:body [user UserRegistration]
(ok)))
和
(POST* "/register" []
:body-params [username :- String,
password :- String]
(ok)))
这两者有什么区别?使用一个与另一个的含义是什么?
唯一的区别在于如何指定参数(以及之后的解构):
body
:
reads body-params into a enhanced let
. First parameter is the let
symbol, second is the Schema to coerced!
against.
Example:
:body [user User]
restructures body-params with plumbing letk
notation.
Example: :body-params [id :- Long name :- String]
根据具体情况,您可能更喜欢其中一种。在这两种情况下,参数(user
在第一种情况下,id
和 name
在第二种情况下)将在主体范围内。
在 compojure-api 中,我注意到这两种指定资源 API 的方法:
(POST* "/register" []
:body [user UserRegistration]
(ok)))
和
(POST* "/register" []
:body-params [username :- String,
password :- String]
(ok)))
这两者有什么区别?使用一个与另一个的含义是什么?
唯一的区别在于如何指定参数(以及之后的解构):
body
:
reads body-params into a enhanced
let
. First parameter is thelet
symbol, second is the Schema tocoerced!
against.Example:
:body [user User]
restructures body-params with plumbing
letk
notation.Example:
:body-params [id :- Long name :- String]
根据具体情况,您可能更喜欢其中一种。在这两种情况下,参数(user
在第一种情况下,id
和 name
在第二种情况下)将在主体范围内。