https://github.com/tlewin/pedestal-controller
Simple controller mechanism for Pedestal applications
https://github.com/tlewin/pedestal-controller
clojure controller pedestal
Last synced: 11 months ago
JSON representation
Simple controller mechanism for Pedestal applications
- Host: GitHub
- URL: https://github.com/tlewin/pedestal-controller
- Owner: tlewin
- License: epl-1.0
- Created: 2019-06-20T20:24:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-01T19:47:21.000Z (over 6 years ago)
- Last Synced: 2025-01-12T22:07:53.878Z (about 1 year ago)
- Topics: clojure, controller, pedestal
- Language: Clojure
- Size: 28.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# pedestal-controller [](https://travis-ci.org/tlewin/pedestal-controller) [](https://clojars.org/pedestal-controller)
Simple controller mechanism for [Pedestal](http://pedestal.io/) applications.
## Usage
The main idea behind controllers is to define a set of
handlers that shares the same interceptors/ settings,
making the entire process less error-prone and easy to maintain.
```clojure
(defcontroller Product
(interceptors [common-interceptors
[auth :only [:create]]
[json-body :except [:search]]])
(handler create
(fn [request]
(let [{{data :data} :params} request]
(ring-resp/response (build-product! data)))))
(handler search
(fn [request]
(let [{{query :query} :params} request]
(ring-resp/response (render (search query)))))))
(interceptors Product) ;; [default auth]
(handlers Product) ;; {:create (fn ...) :search (fn ...)}
(handler Product :create) ;; (fn ... )
```
With the controllers, it's possible to add routes without defining
interceptors configuration:
```clojure
(def routes
(remap-routes
#{["/products" :post Product :create]
["/products/search" :get Product :search]
;; Although it's not mandatory and the old "syntax" still valid.
["/about" :get (conj common-interceptors `about-page)]}))
```
## License
Copyright © 2019 Thiago Lewin
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.