Last active
August 29, 2015 14:05
-
-
Save domkm/26658b53a50e48f0be70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrecord User [id]) | |
; -------------------- | |
; unmatch on Routes | |
(def routes | |
(silk/routes [[User ["users" (silk/integer :id)]]])) | |
(silk/unmatch routes User (User. 42)) ; you can use a record as a params map | |
; or use a helper function to generate a URL | |
(defn unmatch-type [rtes obj] | |
(silk/unmatch rtes (type obj) obj)) | |
; -------------------- | |
; unmatch on Route | |
(def user-route | |
(silk/route [User ["users" (silk/integer :id)]])) | |
(silk/unmatch user-route (User. 42)) | |
; -------------------- | |
; implement `Pattern` and unmatch on type directly | |
(extend-protocol silk/Pattern | |
User | |
(-unmatch [this _] | |
(silk/url {:path ["users" (-> this :id str)]}))) | |
(silk/unmatch (User. 42) {}) | |
; I would consider adding a unary version of `unmatch` if this last one is a common request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment