In compojure-api I noticed this two ways of specifying the API of a resource:
(POST* "/register" []
:body [user UserRegistration]
(ok)))
and
(POST* "/register" []
:body-params [username :- String,
password :- String]
(ok)))
What are the difference between these two? What are the implications of using one vs the other?
The only difference is in how the params are specified (and destructured thereafter):
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]
Depending on the situation you might prefer one or the other. In both cases the params (user
in first case, id
and name
in the second) will be in scope for the body.