grape-api

Sinatra and Grape API together?

五迷三道 提交于 2021-02-05 20:16:32
问题 I've been reading around and I found this micro-framework called Grape for ruby. I am currently using Sinatra to handle the web interface but I would also like to implement Grape to handle the API aspect of the app. I can't find any helpful suggestions to this topic. The grape documentation says "Grape is a REST-like API micro-framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop

Sinatra and Grape API together?

≡放荡痞女 提交于 2021-02-05 20:11:40
问题 I've been reading around and I found this micro-framework called Grape for ruby. I am currently using Sinatra to handle the web interface but I would also like to implement Grape to handle the API aspect of the app. I can't find any helpful suggestions to this topic. The grape documentation says "Grape is a REST-like API micro-framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop

Rails Grape API 'id is invalid' in request that requires no id

Deadly 提交于 2021-01-27 14:07:00
问题 I have a Grape API protected by Doorkeeper and I have a bunch of methods which work perfectly. However, there's one method that behaves weirdly. It is a GET request that requires no parameters and running it throws the following error: Grape::Exceptions::ValidationErrors at /v1/discount_cards/all.json id is invalid My method looks like this: desc 'Get all the cards of current customer' params {} get 'all' do current_customer.discount_cards.to_json(include: { barcode: { include: :barcode_type

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

孤人 提交于 2021-01-02 05:55:42
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

陌路散爱 提交于 2021-01-02 05:55:21
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

自作多情 提交于 2021-01-02 05:55:14
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

grape api ignores PUT/POST params

微笑、不失礼 提交于 2019-12-25 00:58:25
问题 I am building a grape api for a rails app. I am testing it with rspec request specs. I have encountered the problem when making a post route like this: resources :events do segment '/:event_id' do resources :tickets do post do event = current_user.events.find params[:event_id] ...#do sth with event using params[:tickets_ids] the corresponding spec: it "should should return the JSON hash of validated tickets" do post "/api/mobile/#{version}/events/#{event.id}/tickets/", { tickets_ids: [1,2] },

Inheriting class definition from parent class

隐身守侯 提交于 2019-12-24 18:35:39
问题 I am building Grape Entities inside my Rails models as described here: https://github.com/ruby-grape/grape-entity#entity-organization Currently I am creating default values automatically, based on the column hash of the model itself. So I have a static get_entity method that exposes all the model's columns: class ApplicationRecord < ActiveRecord::Base def self.get_entity(target) self.columns_hash.each do |name, column| target.expose name, documentation: { desc: "Col #{name} of #{self.to_s}" }

How to validate this hash parameter?

本秂侑毒 提交于 2019-12-21 05:16:20
问题 How do I write the correct params validations for this hash parameter: { "files": { "main.c": { "contents": "#include <stdio.h> ...", "foo": "bar" }, "main.h": { "contents": "#define BLAH ...", "foo": "baz" }, ... more files here ... } } files is the hash parameter that I want to validate. Each key of files can be anything (a string); the values are hashes with a specific format that also needs to be validated (requires contents and foo ). I'm using grape 0.9.0. This is kind of what I want to

How to create two routes in one block in grape?

与世无争的帅哥 提交于 2019-12-19 11:30:06
问题 I want to catch 2 similar route in one action block. In Rails5 I can do that easily. I first declare this: get ':folder/:file' => 'get#index', :file => /.*/, :folder => /.*/ get ':file' => 'get#index', :file => /.*/ This allows me to catch :folder as much as folder can be like a/b/c/d... and :file at end one last filename. Second one also allow me to only catch filenames. And both routes target to same action. However, In Grape because it is declared as blocks rather than route to method