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
7
votes
1 answer

Grape: Rescue from invalid JSON

First: I'm using grape for building my API (Rails 4). When someone is sending an invalid JSON body (e.g. forgot the last }), the following error is raised: ActionDispatch::ParamsParser::ParseError (795: unexpected token at '{"foobar": 1234 ') I…
23tux
  • 14,104
  • 15
  • 88
  • 187
7
votes
1 answer

Why does mounting a route in Rails fail with "uninitialized constant API"?

I am working on an app that includes an API that is using the grape gem. Here is my Root Class: module API class Root < Grape::API rescue_from :all do |e| Rack::Response.new( [ "Error: #{e.message}" ], 500, {…
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
7
votes
2 answers

Grape entities conditional expose if field is NOT nil

In a grape-entity, I want to show a field only if present (not nil?) with no luck. I'm trying this code but doesn't work as expected at all, but hiding the field always. expose :winner, :using => PlayerEntity, :unless => { :winner => nil } I think…
Jorge Diaz
  • 2,503
  • 1
  • 14
  • 15
6
votes
1 answer

How to apply ActiveSupport::Concern to specific actions in my controller?

I'm using Grape to build an API. I created an ActiveSupport::Concern let's say with the name Authentication and I applied some before filter so my concern looks like: module Authentication extend ActiveSupport::Concern included do before…
Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81
6
votes
2 answers

Set status code in Grape gem

How does one customise the status code response when using the Grape gem? e.g. post do status = :accepted @order = Order.find(params[:id]) end This can be achieved for with error!({ error: 'Order not found'}, 404) but how does one do it for…
TrevTheDev
  • 2,616
  • 2
  • 18
  • 36
5
votes
0 answers

grape - table read as a constant

I'm using rails 5 and grape for api, I'm trying to create grape endpoint for the table application. module PROJ::API::V2 class Applications < ::Grape::API get '/' do authorize! :read, Application status 200 present…
Anbazhagan p
  • 943
  • 1
  • 14
  • 27
5
votes
1 answer

Why doesn't session[:] work in grape - rails?

I'm using Rails with Grape as API. I was just curious why there isn't session[:something] method in grape? I can create cookies but can't created signed cookies either. It throw me an error.
Ninja Boy
  • 1,112
  • 3
  • 14
  • 28
5
votes
0 answers

How To Use authenticate_or_request_with_http_token With Grape?

how can I implement authenticate_or_request_with_http_token in grape API. Below is my code : module Articles class ArticleData < Grape::API include ActionController::HttpAuthentication::Token::ControllerMethods # http_basic do…
Mohamad Afiq
  • 275
  • 1
  • 5
  • 14
5
votes
1 answer

How to connect Rails Grape API with Ember reflexive model

I'm having a problem with connecting Json payload from Grape (serialized with Grape entity) with Ember reflexive model. Model looks like this: Category = DS.Model.extend { name: DS.attr 'string', children: DS.hasMany 'category', inverse:…
szsoppa
  • 113
  • 5
5
votes
0 answers

rails + grape: stop serving request after timeout?

When a request takes longer than the timeout limit, the client will receive a 503 response; yet, the server keeps wasting resources (that would be better used on other requests) to create a response that will then be thrown away. Is there a…
giorgian
  • 3,795
  • 1
  • 30
  • 48
5
votes
1 answer

Inheritance is not working in grape

I am using grape redtful-api. I am Unable to inherit common_params in Grape. I defined common _params in class API1 and called it in API2 throws the error. How can I change the code to make this work? module Example class API1 < Grape::API …
Sam
  • 5,040
  • 12
  • 43
  • 95
4
votes
0 answers

Ruby GraphQL: Running Filters and calling custom methods on Embedded Objects

I was following an absolutely stellar tutorial on building a GraphQL API on https://www.howtographql.com/graphql-ruby/0-introduction/ My API framework is Grape, and Mongoid is my Database framework but works very similar to rails because it uses…
alilland
  • 2,039
  • 1
  • 21
  • 42
4
votes
2 answers

Grape, sending JSON as params

My Grape API accepts json format and I have method that accepts JSON as parameter: desc 'JSON test' params do requires :json, type: JSON end post :json_test do json = params[:json] {result: json} end When I make request via postman,…
Mr.D
  • 7,353
  • 13
  • 60
  • 119
4
votes
1 answer

Mongoid; ERROR Mongo::Error::OperationFailure: not authorized for query

I am creating an application using ruby/grape and mongoid. But when I try to create or find a document in any collection using mongoid, for example with Admin.create I get the following error: ERROR Mongo::Error::OperationFailure: not authorized for…
Haider
  • 254
  • 1
  • 10
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
1
2
3
25 26