3

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?

4

1 回答 1

5

The only difference is in how the params are specified (and destructured thereafter):

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]

body-params:

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.

于 2015-08-01T23:26:11.163 回答