-
Notifications
You must be signed in to change notification settings - Fork 134
/
macros.clj
24 lines (23 loc) · 1.12 KB
/
macros.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
(ns ajax.macros)
(defmacro easy-api [method]
(let [uri (symbol "uri")
opts (symbol "opts")
easy-ajax-request (symbol "ajax.easy/easy-ajax-request")]
`(defn ~method
"accepts the URI and an optional map of options, options include:
:handler - the handler function for successful operation
should accept a single parameter which is the
deserialized response
:progress-handler - the handler function for progress events.
this handler is only available when using the goog.net.XhrIo API
:error-handler - the handler function for errors, should accept a
map with keys :status and :status-text
:format - the format for the request
:response-format - the format for the response
:params - a map of parameters that will be sent with the request"
[~uri & ~opts]
(let [f# (first ~opts)]
(~easy-ajax-request ~uri ~(name method)
(if (keyword? f#)
(apply hash-map ~opts)
f#))))))