ruby-grape / grape-with-roar Goto Github PK
View Code? Open in Web Editor NEWA demo of using Grape with Roar and some non-trivial HAL presenters.
License: MIT License
A demo of using Grape with Roar and some non-trivial HAL presenters.
License: MIT License
This doesn't work (on the with-mongoid branch) for _post
.
require 'hyperclient'
client = Hyperclient.new('http://localhost:9292/api')
3.times do |i|
client.splines._post(spline: { name: i.to_s, reticulated: [true, false].sample })
end
client.splines.each do |spline|
puts "spline #{spline.id} #{spline.reticulated ? 'is' : 'is not'} reticulated"
end
client.splines.each(&:_delete)
Demo processing POSTed JSON.
If you see here: http://haltalk.herokuapp.com/explorer/browser.html#/, the links are relative like /users
but this project uses full paths like http://domain.com/splines
, does it matter?
I use this project as a template, except I use activerecord
:
get 'articles' do
# ActiveRecord::Relation
articles = Articles.all
# articles.respond_to?('merge') == true
present articles, with: ArticlesPresenter
end
This crashes because of this change.
Because the opts
parameter is empty:
link :self do |opts|
"#{base_url(opts)}/api"
end
Though it's not a problem for this project because splines
is an array and it doesn't respond_to?('merge')
.
get do
splines = Acme::Models::Spline.all
present Kaminari.paginate_array(splines).page(params[:page]).per(params[:size]), with: Acme::Api::Presenters::SplinesPresenter
end
I can't understand further, please fix this, here's a full stack trace:
NoMethodError:
undefined method `[]' for nil:NilClass
Shared Example Group: "paginated resource" called from ./spec/app/api/article_spec.rb:4
# ./app/presenters/paginated_presenter.rb:33:in `request_url'
# ./app/presenters/paginated_presenter.rb:16:in `block in <module:PaginatedPresenter>'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:80:in `instance_exec'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:80:in `run_link_block'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:68:in `block in compile_links_for'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:66:in `collect'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:66:in `compile_links_for'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:62:in `prepare_links!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/hypermedia.rb:139:in `block in create_links_definition!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/uber-0.0.12/lib/uber/options.rb:80:in `instance_exec'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/uber-0.0.12/lib/uber/options.rb:80:in `proc!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/uber-0.0.12/lib/uber/options.rb:69:in `evaluate_for'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/uber-0.0.12/lib/uber/options.rb:60:in `evaluate'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/binding.rb:107:in `evaluate_option'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/binding.rb:80:in `get'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/binding.rb:37:in `block in compile_fragment'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/binding.rb:100:in `evaluate_option'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/binding.rb:36:in `compile_fragment'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/mapper.rb:64:in `compile_fragment'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/roar-1.0.0/lib/roar/json/hal.rb:64:in `compile_fragment'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/mapper.rb:30:in `serialize_property'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/mapper.rb:22:in `block in serialize'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/mapper.rb:21:in `each'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/mapper.rb:21:in `serialize'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable.rb:41:in `create_representation_with'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/representable-2.1.3/lib/representable/hash.rb:35:in `to_hash'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/dsl/inside_route.rb:200:in `merge'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/dsl/inside_route.rb:200:in `present'
# ./app/api/articles.rb:20:in `block in <class:Articles>'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:47:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:47:in `block in generate_api_method'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:247:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:247:in `run'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:195:in `block in call!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/base.rb:24:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/base.rb:24:in `call!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/base.rb:18:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/base.rb:24:in `call!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/base.rb:18:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/error.rb:27:in `block in call!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/error.rb:26:in `catch'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/error.rb:26:in `call!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/middleware/base.rb:18:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0/lib/rack/head.rb:13:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-1.6.0/lib/rack/builder.rb:153:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:196:in `call!'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/endpoint.rb:184:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:75:in `optimized_each'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:75:in `optimized_each'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/grape-0.10.1/lib/grape/api.rb:102:in `call'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /home/ubuntu/.rvm/gems/ruby-2.1.3/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
# ./spec/app/api/shared_examples/resource.rb:34:in `block (3 levels) in <top (required)>'
With cursor-based pagination, see codegram/hyperclient#106.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.