-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathhandler.clj
61 lines (51 loc) · 1.53 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(ns compojure.handler
"Functions to create Ring handlers from routes.
This namespace has been **DEPRECATED** in favor of the [ring-defaults][]
library.
[ring-defaults]: https://github.com/ring-clojure/ring-defaults"
{:deprecated "1.2"}
(: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"
{:deprecated "1.2"}
[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"
{:deprecated "1.2"
:arglists '([routes] [routes options])}
[routes & [opts]]
(-> (api routes)
(with-opts wrap-multipart-params (:multipart opts))
(wrap-flash)
(with-opts wrap-session (:session opts))))