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
irb(main)> resource = Restfulie.at('http://localhost:3000/items').get.resource | |
Response: | |
ready to execute request using stack typeRestfulie::Client::Feature::BaseRequestargstypeRestfulie::Client::Feature::RescueExceptionargstypeRestfulie::Client::Feature::SetupHeaderargstypeRestfulie::Client::Feature::SerializeBodyargstypeRestfulie::Client::Feature::EnhanceResponseargstypeRestfulie::Client::Feature::FollowRequestargs | |
invoking filter Restfulie::Client::Feature::FollowRequest with #<Restfulie::Client::Dsl:0xb708ff7c> at | |
invoking filter Restfulie::Client::Feature::EnhanceResponse with #<Restfulie::Client::Dsl:0xb708ff7c> at | |
invoking filter Restfulie::Client::Feature::SerializeBody with #<Restfulie::Client::Dsl:0xb708ff7c> at | |
invoking filter Restfulie::Client::Feature::SetupHeader with #<Restfulie::Client::Dsl:0xb708ff7c> at | |
invoking filter Restfulie::Client::Feature::RescueException with #<Restfulie::Client::Dsl:0xb708ff7c> at |
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
member(@item) do |m| | |
m.link "self", item_url(@item) | |
m.values { |v| | |
v.name @item.name | |
v.price @item.price} | |
end |
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
collection(@items, :root => "items") do |items| | |
items.link "self", items_url | |
# setting :root is unnecessary here but is useful for customizing element names. | |
items.members(:root => "item") do |m, item| | |
m.link :self, item_url(item) | |
m.values { |values| | |
values.name item.name | |
values.price item.price } | |
end | |
end |
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
// To create a new item using Restfulie | |
irb(main)> resource = Restfulie.at('http://localhost:3000/items').as("application/xml").post!(:item => { :name => "Mobile", :price => 5000}) | |
// To access newly created Item | |
irb(main)> p resource.resource.item.name | |
"Mobile" | |
=> nil |
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
def show | |
respond_with @item = Item.find(params[:id]) | |
end | |
def create | |
@item = Item.create(params[:item]) | |
render :text => "", :status => 201, :location => item_url(@item) | |
end |
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
irb(main)> response = Restfulie.at('http://localhost:3000/items').accepts('application/json').get | |
Output: | |
ready to execute request using stack | |
typeRestfulie::Client::Feature::BaseRequestargstypeRestfulie::Client::Feature::RescueExceptionargstypeRestfulie::Client::Feature::SetupHeaderargstypeRestfulie::Client::Feature::SerializeBodyargstypeRestfulie::Client::Feature::EnhanceResponseargstypeRestfulie::Client::Feature::FollowRequestargs | |
invoking filter Restfulie::Client::Feature::FollowRequest with #<Restfulie::Client::Dsl:0xb6a12d5c> at | |
invoking filter Restfulie::Client::Feature::EnhanceResponse with #<Restfulie::Client::Dsl:0xb6a12d5c> at | |
invoking filter Restfulie::Client::Feature::SerializeBody with #<Restfulie::Client::Dsl:0xb6a12d5c> at | |
invoking filter Restfulie::Client::Feature::SetupHeader with #<Restfulie::Client::Dsl:0xb6a12d5c> at |
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
curl -i "http://localhost:3000/items" -H "Accept:application/json" | |
HTTP/1.1 200 OK | |
X-Ua-Compatible: IE=Edge | |
Etag: "579a54772674bf702106c51fc48d9d2b" | |
Connection: Keep-Alive | |
Content-Type: application/json; charset=utf-8 | |
Date: Fri, 08 Apr 2011 08:50:52 GMT | |
Server: WEBrick/1.3.1 (Ruby/1.8.7/2008-08-11) | |
X-Runtime: 0.655732 |
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
Item.create :name => "Pendrive", :price => "500" | |
Item.create :name => "Laptop", :price => "25000" |
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
> curl -i "http://localhost:3000/items" | |
RESPONSE : | |
HTTP/1.1 200 OK | |
X-Ua-Compatible: IE=Edge | |
Etag: "4f31ca96db448bb738a3923db737871d" | |
Connection: Keep-Alive | |
Content-Type: application/xml; charset=utf-8 | |
Date: Fri, 08 Apr 2011 08:47:08 GMT |
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
class ItemsController < ApplicationController | |
// To notify Rails that we are capable of handling xml and json request | |
respond_to : xml, :json | |
// To notify that this controller behave as a Restfulie controller | |
acts_as_restfulie | |
def index | |
@items = Item.all | |
respond_with @items |
NewerOlder