Questions tagged [ruby-grape]

Grape lets you quickly add maven repository dependencies to your classpath OR Grape is a REST-like API micro-framework written in Ruby to sit on top of Rack.

Grape is a framework that allows for quickly defining REST-like interfaces in Ruby. It provides a DSL for defining versioned APIs as a collection of entities mounted on Rack.

385 questions
4
votes
1 answer

Request to Grape API for rails block other requests

For my rails app I set up an API with gem Grape. I add a test post method that the code sleeps 10 seconds and returns {'status'=>'success'}. Everything works except that the API call seems to block all other requests sent to the server. Any other…
wyncg
  • 53
  • 4
4
votes
1 answer

How to validate this hash parameter?

How do I write the correct params validations for this hash parameter: { "files": { "main.c": { "contents": "#include ...", "foo": "bar" }, "main.h": { "contents": "#define BLAH ...", "foo": "baz" …
Decade Moon
  • 32,968
  • 8
  • 81
  • 101
4
votes
1 answer

How to pass a Hash to Grape API method?

I'm having problems with the Grape gem and the parameters validation. The idea behind this is to create a complex entity using nested attributes through an API service. I have a method to create a trip, trip have many destinations and i want to…
halbano
  • 1,135
  • 14
  • 34
4
votes
1 answer

how does rails ActiveModel::Serializers compare to grape?

Can someone explain the difference between ActiveModel::Serializers and Grape. Should I use one or the other or could/should they be used together. Could someone also explain the benefits of using one (or both) of the above versus just using rails…
4
votes
3 answers

passing argument to model method with grape-entity

How can I pass an argument to a model method using grape entity ? I'd like to check wheter the current_user likes an item when presenting the item, so I built a model user_likes? method: class Item include Mongoid::Document #some attributes…
aherve
  • 3,795
  • 6
  • 28
  • 41
4
votes
2 answers

Parsing Hashie::Mash output to Json in ruby

I'm getting user input in JSON format for an API created using grape. In a particular parameter, I'm giving an array of JSON in the following format. "personal" : { "details" : { "firstname" :"nagalakshmi", "lastname" : "n" } } When I…
NagaLakshmi
  • 715
  • 3
  • 12
  • 24
4
votes
2 answers

Activerecord associations as JSON with Grape

Is there a simple way to return activerecord models with associations as JSON using the Grape microframework? get 'users' do User.includes(:address) end This snippet isn't working and User.includes(:address).to_json(include: :address) will get…
schickling
  • 4,000
  • 4
  • 29
  • 33
4
votes
3 answers

How to return an empty response with grape?

I have a format :xml Grape::API and for a delete request I want to return an empty response. Everything I try to enter though, true, false, nil, it tries to convert to xml. How would I go about doing this? Thanks
Tallboy
  • 12,847
  • 13
  • 82
  • 173
4
votes
2 answers

Stubbing Grape helper

I have Rails app with Grape API. The interface is done with Backbone and Grape API provides it all data. All it returns is user-specific stuff, so i need reference to currently logged in user. Simplified version looks like this: API…
pipboy3k
  • 123
  • 2
  • 10
3
votes
0 answers

ArgumentError: expected attributes to be able to convert to Hash, got []

I got this error in active-resource using grape gem with an entity. I got this result on the…
Dipali Nagrale
  • 510
  • 5
  • 17
3
votes
0 answers

How to exclude grape middleware from just 1 API?

I have implemented a custom Grape middleware for authentication. I need to exclude it from the APIs meant for Login/Signup. Is there any neat way to do this?
3
votes
2 answers

Rspec interprets empty array as lack of parameter with Grape

I have a Ruby (non-Rails) app that uses Grape to expose API endpoints. One of the endpoints requires a parameter that is an array of values, but accepts an empty array as well: requires :user_ids, type: Array, allow_blank: true This all works fine…
Sandworm
  • 131
  • 8
3
votes
1 answer

How to use grape-entity without grape-api?

I am trying to use grape-entity without the grape-api gem. So just use it as a serializers for raw rails controllers. When trying to present my resource by doing: present User.all, with: Entities::User I get that the present method is undefined How…
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
3
votes
0 answers

How to include subdirectories to autoload for Grape API?

I'm using Grape to build an API for a Rails project (I'm mounting the grape project in rails routes.rb something like mount Backend::Base => '/'). The files structure is something like: ├── app │   ├── api │   │   └── backend │   │   ├──…
Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81
3
votes
1 answer

Rails: ruby class name must base on file name?

I'm learning rails 5.0. When I learn Ruby, I know that ruby file name can be different with class name inside. But when I move to rails, I see that ruby file name and class name must have same format. For example, a class name CheckInDetail will be…
Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107
1 2
3
25 26