Created
April 27, 2012 07:55
-
-
Save ayamomiji/2507180 to your computer and use it in GitHub Desktop.
rest http client idea
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
# client usage | |
client.resources('/articles').post # => POST /articles | |
client.articles.post # => POST /articles | |
client.article(1).get # => GET /articles/1 | |
client.article(1).comments.get # => GET /articles/1/comments | |
client.admin # => client with admin support (for example, use http basic auth middleware) | |
client.admin.articles.get # => GET /admin/articles with http basic auth | |
# client define | |
use WhateverMiddleware | |
resources :articles do | |
resources :comments | |
end | |
scope :admin do | |
use HTTPBasicAuth, 'user', 'secret' | |
resources :articles do | |
resources :comments | |
end | |
end | |
# or... | |
class AdminClient | |
extend Client | |
use HTTPBasicAuth, 'user', 'secret' | |
resources :articles do | |
resources :comments | |
end | |
end | |
class MainClient | |
extend Client | |
use WhateverMiddleware | |
resources :articles do | |
resources :comments | |
end | |
scope :admin => AdminClient | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment