Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

REST Adapter for DataMapper

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 tasks
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 dm-rest-adapter.gemspec


A DataMapper adapter for REST Web Services


DM Rest Adapter requires the use of a model which is the same name as the resource you are using. For example, if you have a resource named “posts” you will create a standard datamapper object called post.rb in app/models. The only difference in this model is you will need to define the rest adapter for the model.

The following is an example of a post model, where the host settings point to the app you are running the resource on. In addition I have included a basic auth login which will be used if your resource requires auth:

DataMapper.setup(:default, {
  :adapter  => 'rest',
  :format   => 'xml',
  :host     => 'localhost',
  :port     => 4000,
  :login    => 'user',
  :password => 'verys3crit'

class Post

  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :body,  Text


If you notice this looks exactly like a normal datmapper model. Every property you define will map itself with the xml returned or posted from/to the resource.


Now for some code examples. DM Rest Adapter uses the same methods as datamapper including during creation.

# => returns the object from the resouce
# => returns the object from the resource
p = => "My awesome blog post", :body => "I really have nothing to say...")
# => saves the resource on the remote


Posts do not honor RESTful HTTP status codes. I might fix this…


Nested resources Put verb actions

Something went wrong with that request. Please try again.