mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
Updated compojure per weavejester's suggestions
This commit is contained in:
parent
fc84512fa6
commit
014262f5c6
@ -81,18 +81,26 @@ The body may be a function, which must accept the request as a parameter:
|
||||
(GET "/" [] (fn [req] "Do something with req")))
|
||||
```
|
||||
|
||||
Route patterns may include named parameters,
|
||||
Or, you can just use the request directly:
|
||||
|
||||
```clojure
|
||||
(defroutes myapp
|
||||
(GET "/" req "Do something with req"))
|
||||
```
|
||||
|
||||
Route patterns may include named parameters:
|
||||
|
||||
```clojure
|
||||
(defroutes myapp
|
||||
(GET "/hello/:name" [name] (str "Hello " name)))
|
||||
```
|
||||
|
||||
You can match entire paths with *
|
||||
You can adjust what each parameter matches by supplying a regex:
|
||||
|
||||
```clojure
|
||||
(defroutes myapp
|
||||
(GET "/file/*.*" [*] (str *)))
|
||||
(GET ["/file/:name.:ext" :name #".*", :ext #".*"] [name ext]
|
||||
(str "File: " name ext))
|
||||
```
|
||||
|
||||
Handlers may utilize query parameters:
|
||||
@ -123,7 +131,7 @@ Or, for POST and PUT requests, form parameters
|
||||
The return value of a route block determines at least the response body
|
||||
passed on to the HTTP client, or at least the next middleware in the
|
||||
ring stack. Most commonly, this is a string, as in the above examples.
|
||||
But, you may also return a [response body](https://github.com/mmcgrana/ring/blob/master/SPEC):
|
||||
But, you may also return a [response map](https://github.com/mmcgrana/ring/blob/master/SPEC):
|
||||
|
||||
```clojure
|
||||
(defroutes myapp
|
||||
@ -222,4 +230,6 @@ You can easily read in templates from your resources directory. Here's a helper
|
||||
|
||||
Further reading:
|
||||
|
||||
[Clojure for the Brave and True](http://www.braveclojure.com/)
|
||||
* [Official Compojure Documentation](https://github.com/weavejester/compojure/wiki)
|
||||
|
||||
* [Clojure for the Brave and True](http://www.braveclojure.com/)
|
||||
|
Loading…
Reference in New Issue
Block a user