`request` object in Compojure routes

1,422 views
Skip to first unread message

Shantanu Kumar

unread,
Jun 11, 2011, 3:11:16 PM6/11/11
to Clojure Web Development
Hi,

I want to access the request object (and :session object thereafter)
in a Compojure route -- how can I acces it? The de-structuring
examples seem to talk only about parameters, not the request object.

Regards,
Shantanu

Robert Marianski

unread,
Jun 11, 2011, 3:31:29 PM6/11/11
to clojure...@googlegroups.com

Using destructuring to get the session and request, you can do something
like:

(GET "/foo" {session :session :as request} (foo session request))

Robert

James Reeves

unread,
Jun 11, 2011, 3:33:50 PM6/11/11
to clojure...@googlegroups.com

There's a detailed explanation of Compojure destructuring here:

https://github.com/weavejester/compojure/wiki/Destructuring-Syntax

But briefly, you can write:

(GET "/" request ...)

(GET "/" {:as request} ...)

(GET "/" [:as request] ...)

(GET "/" {session :session} ...)

(GET "/" [:as {session :session}] ...)

- James

Reply all
Reply to author
Forward
0 new messages