Skip to content

Add possibility for reuse to defresource#97

Merged
ordnungswidrig merged 2 commits intoclojure-liberator:masterfrom
stijnopheide:defresource-reuse
Feb 23, 2014
Merged

Add possibility for reuse to defresource#97
ordnungswidrig merged 2 commits intoclojure-liberator:masterfrom
stijnopheide:defresource-reuse

Conversation

@stijnopheide
Copy link

Adding the possibility for reuse as discussed on the mailing list

see https://groups.google.com/forum/#!topic/clojure-liberator/CKl2lPp-3ZY

example usage:

;; still compatible with the old format
(defresource without-param
  :handle-ok (fn [_] (format "The text is %s" "test")))

(defresource parameter [txt]
  :handle-ok (fn [_] (format "The text is %s" txt))
  :available-media-types ["application/xml"])

;; how to introduce reuse
(def standard-config
  {:available-media-types ["application/json"]})

(defresource with-options
  standard-config
  :handle-ok (fn [_] (format "The text is %s" "this")))

(defresource with-options-and-params [txt]
  standard-config
  :handle-ok (fn [_] (format "The text is %s" txt))
  :available-media-types ["application/xml"])  ;; this actually overrides the standard-config

;; you can also add a parametrized config
(defn parametrized-config
  [media-type]
  {:available-media-types [media-type]})

(defresource with-options-parametrized-config [media-type txt]
  (parametrized-config media-type)
  :handle-ok (fn [_] (format "The text is %s" txt)))

Stijn Opheide added 2 commits January 9, 2014 17:35
…unction with the request as parameter, instead of a function with 0 arguments that returns a function of request.
jeluard added a commit to jeluard/lucuma that referenced this pull request Jan 14, 2014
@ordnungswidrig
Copy link
Member

I like your patch. I prepare a local branch of this that will be a good candidate to be merged with master. I shuffled the macro expansion logic a bit such that resource can handle a standard-config as well.

@ordnungswidrig
Copy link
Member

ordnungswidrig added a commit that referenced this pull request Feb 23, 2014
@ordnungswidrig ordnungswidrig merged commit cef27ea into clojure-liberator:master Feb 23, 2014
@stijnopheide stijnopheide deleted the defresource-reuse branch February 24, 2014 08:57
belucid added a commit to SnootyMonkey/Falkland-CMS that referenced this pull request Aug 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants