A Grape API that uses Roar and Mongoid with a MongoDB database.
$ bundle install
$ rackup
[2013-06-20 08:57:58] INFO WEBrick 1.3.1
[2013-06-20 08:57:58] INFO ruby 1.9.3 (2013-02-06) [x86_64-darwin11.4.2]
[2013-06-20 08:57:58] INFO WEBrick::HTTPServer#start: pid=247 port=9292
Try with Hyperclient and irb.
require 'hyperclient'
Create some splines.
client = Hyperclient.new('http://localhost:9292/api')
3.times do |i|
client.splines._post(spline: { name: i.to_s, reticulated: [true, false].sample })
endShow splines.
client = Hyperclient.new('http://localhost:9292/api')
client.splines.each do |spline|
puts "spline #{spline.id} #{spline.reticulated ? 'is' : 'is not'} reticulated"
endDelete splines.
client = Hyperclient.new('http://localhost:9292/api')
client.splines.each(&:_delete)Navigate to localhost:9292/api with a browser. This is a hypermedia API, so all links are clickable.
This is a good demo to use with Hyperclient. Check out splines_endpoint_with_hyperclient_spec.rb for a complete example that retrieves, creates, updates and deletes splines.
This project uses Mongoid and defines a dummy Spline class. Check out the master branch for a complete example that uses ActiveModel and with-activerecord branch for a complete example that uses ActiveRecord and a PostgreSQL database.
Copyright (c) 2014-2016 Daniel Doubrovkine
MIT License, see LICENSE for details.