Questions tagged [grape-api]

Grape is a Ruby Gem that provides a DSL to easily develop RESTful APIs.

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 RESTful APIs.

307 questions
4
votes
1 answer

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

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…
Denis Yakovenko
  • 3,241
  • 6
  • 48
  • 82
4
votes
1 answer

NoMethodError: undefined method in routes_with_grape

I am trying to set up a rails grape api with the below structure. app api api V1 user.rb app.rb I am getting this error when i run routes_with_grape rake aborted! NoMethodError: undefined method `ast' for…
Kanishka
  • 1,097
  • 5
  • 20
  • 37
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

How to write same requirements for multiple routes e.g. POST, PUT? (Ruby Grape)

How can I avoid duplicate code? resource 'api/publication/:publicationName' do params do requires :type, type: String, regexp: /^(static|dynamic)$/i requires :name, type: String, regexp: /^[a-z0-9_\s]+$/i requires :liveStartDate,…
hfossli
  • 22,616
  • 10
  • 116
  • 130
4
votes
3 answers

Where do I place Swagger-UI in a Rails App with Grape?

I am re-writing (yeah I know!) a Rails app which is largely API driven, using Grape by Intridea and grape-swagger gem to enable Swagger UI for documentation. So I have a simple hello world app running. Seems discoverable from the swagger test,…
Richard Jordan
  • 8,066
  • 3
  • 39
  • 45
4
votes
1 answer

Implementing hypermedia-driven API with Grape (or Sinatra)

I'm trying to implement a hypermedia-driven API using Grape mounted directly on top of Rack. Grape supports presenters ("entities") which seem to be the proper place for providing all related hypermedia. If I had Rails router available, I could…
4
votes
2 answers

How could we separate grape api resources into multiple files?

Hi I am developing a simple api in ruby using intridea's grape. Let's say we have this: class API_v1 < Grape::API resource :foo do end resource :bar do end end How could I make it so that the declaration for :foo and :bar are in separate…
Lester Celestial
  • 1,454
  • 1
  • 16
  • 26
3
votes
0 answers

Upload document using grape api | ArgumentError (missing keyword: io)

I am trying to upload image using grape api. I have done the following steps. rails active_storage:install rails g model user name email avatar:attachment rails db:migrate module API module V1 class Users < Grape::API include…
sel
  • 169
  • 5
  • 13
3
votes
0 answers

API documentation - How to give response schema using rabl with grape-api

We are using grape for APIs and grape-rabl for responses in our Rails application. Now we are in the process of documenting the APIs, and we use grape-swagger for it. But we do not know how to document the response schema for the API endpoints. The…
sureshprasanna70
  • 1,043
  • 1
  • 10
  • 27
3
votes
2 answers

How to add public API to a Rails app?

I'd like to open my Rails 2.3 app (hosted on Heroku) to developers. I thought of two ways of doing this: Using the respond_to |format| of the app, and a before_filter only allowing authorized developers API keys Using a second Heroku account…
martini-bonanza
  • 1,515
  • 3
  • 18
  • 33
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
1 2
3
20 21