-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcompojure_handler.clj
46 lines (42 loc) · 1.29 KB
/
compojure_handler.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(ns compojure.handler
"Functions to create Ring handlers from routes."
(:use [ring.middleware params
keyword-params
nested-params
multipart-params
cookies
session
flash]))
(defn- with-opts [routes middleware opts]
(if opts
(middleware routes opts)
(middleware routes)))
(defn api
"Create a handler suitable for a web API. This adds the following
middleware to your routes:
- wrap-params
- wrap-nested-params
- wrap-keyword-params"
[routes]
(-> routes
wrap-keyword-params
wrap-nested-params
wrap-params))
(defn site
"Create a handler suitable for a standard website. This adds the
following middleware to your routes:
- wrap-session
- wrap-flash
- wrap-cookies
- wrap-multipart-params
- wrap-params
- wrap-nested-params
- wrap-keyword-params
A map of options may also be provided. These keys are provided:
:session - a map of session middleware options
:multipart - a map of multipart-params middleware options"
[routes & [opts]]
(-> (api routes)
(with-opts wrap-multipart-params (:multipart opts))
(wrap-flash)
(with-opts wrap-session (:session opts))))