Skip to content

Instantly share code, notes, and snippets.

@ayamomiji
Created April 27, 2012 07:55
Show Gist options
  • Save ayamomiji/2507180 to your computer and use it in GitHub Desktop.
Save ayamomiji/2507180 to your computer and use it in GitHub Desktop.
rest http client idea
# 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