If you build simple json API, combining validation function which return
validation error as a map and clojure.lang.ExceptionInfo can
reduce intermediate error handling code.
(when-let [m (validate params)]
(throw (clojure.lang.ExceptionInfo. "validation error" m)))
(defn wrap-validation-exception [handler]
(fn [req]
(try
(handler req)
(catch clojure.lang.ExceptionInfo e
{:status 400
:headers {"Content-Type" "application/json"}
:body (some-json-generator (.getData e))}))))
On Monday, July 23, 2012 8:46:52 AM UTC+9, larry google groups wrote:
>
> Since 2000 I've been doing web development, first with PHP and then with
> Ruby On Rails. In the world of PHP, there are some frameworks, such as
> Symfony, that have classes for managing forms, both generating the HTML for
> the forms, and also handling the validation of the forms. In the world of
> Python, the Django framework also has facilities for generating and
> validating forms. These frameworks offer certain time saving conveniences.
> For instance, with the Symfony framework, if you have a database table that
> has a foreign key, then you can get that other table (the target of the
> foreign key) to appear in a form as a pre-populated select box,
> automatically (after filling out some config files).
>
> I'm now trying to make Clojure my primary development language for
> everything, including web development. I'm curious, are there any libraries
> in the land of Clojure that offer similar conveniences for forms?
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en