Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility for reuse to defresource #97

Merged

Conversation

stijnopheide
Copy link

@stijnopheide stijnopheide commented Jan 9, 2014

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)))

stijnopheide added 2 commits Jan 9, 2014
…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 issue Jan 14, 2014
@ordnungswidrig
Copy link
Member

@ordnungswidrig ordnungswidrig commented Feb 11, 2014

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 added a commit that referenced this issue Feb 23, 2014
@ordnungswidrig ordnungswidrig merged commit cef27ea into clojure-liberator:master Feb 23, 2014
1 check passed
@stijnopheide stijnopheide deleted the defresource-reuse branch Feb 24, 2014
belucid added a commit to SnootyMonkey/Falkland-CMS that referenced this issue 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.

None yet

2 participants