clojureswaggerplumatic-schemacompojure-api

What is the difference between body and body-params in compojure-api?


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?


Solution

  • 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.