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

XML instead of JSON with Grape, Rails 3 and Heroku

I am using Grape (https://github.com/intridea/grape) with Rails 3 and i am experiencing a strange problem. I defined json as the default output format in my API class, and i am using the as_json method to output my results. In my…
mathieurip
  • 547
  • 1
  • 6
  • 16
0
votes
2 answers

Rails3 api to retrieve items based on its params using grape

i m working in rails 3 i have a doubt , i have a method to fetch the items based on its tag like resources "blogs" do get '/tag', '/tag/:name' do authenticate! tag_name = params[:name].to_s || "" # query to fetch from items based on…
useranon
  • 29,318
  • 31
  • 98
  • 146
0
votes
1 answer

How to add spec test to grape api in rails 2.3?

all I want to add rspec tests to grape API. and our app is still on rails 2.3.8 . for the rspec 2+ , we have that solution. https://github.com/dblock/grape/commit/99bf4b44c511541c0e10f4506bf34ae9abcccd75 but is there a solution rspec 1.3? As…
dexterdeng
  • 249
  • 3
  • 13
0
votes
2 answers

How to return text with line break with Grape API?

I am trying to create an endpoint where the response body is just a string with line breaks, but the response keeps showing the \n character. My endpoint code: get '' do header('Content-Type', 'text/plain') body("Hello\nWorld") end And this is…
joaopribs
  • 648
  • 1
  • 7
  • 13
0
votes
1 answer

Rails [Grape::API] How to include meta object when using error! method?

I am using Grape::API gem to build APIs and responses. I figured a way to add the meta object to the response body when responding using present method. It is something like this: present meta: { key: "value" } present user, with:…
Ayush Poddar
  • 106
  • 5
0
votes
0 answers

How to set type and desc params with a function with Grape/Rails API

I am writing an API with Grape for may Rails 6 application. I have a model with custom columns (depending on specification). I generate a patch request parameters list, and I would like to generate desc and type with a function. But I do not know if…
LiKaZ
  • 306
  • 3
  • 9
0
votes
0 answers

Sending Array of string in grape API

Using grape api, I try to send an array of string but I always have the response error, codes is not valid In my model, I expose my field like this : expose :code, documentation: { type: Array[String]} And when I make my test, I pass "code": [ …
Damien Compère
  • 219
  • 1
  • 3
  • 16
0
votes
1 answer

How do I override the root key in a Grape API response payload?

module Entities class StuffEntity < Grape::Entity root 'stuffs', 'stuff' ... How can I DRY up my code by reusing this entity while still having the flexibility to rename the root keys ('stuffs' and 'stuff') defined in the entity? I might…
Allison
  • 1,925
  • 1
  • 18
  • 25
0
votes
1 answer

Rails Grape ActionController::RoutingError (No route matches [GET] "/api/v1/user_locations"):

I have used the grape and swagger for Rails backend - API application Rails 6 I have used the following gems for the gem 'grape' gem 'grape-swagger' gem 'grape-swagger-rails' gem 'grape-jbuilder' I have created one controller UserLocations module…
urjit on rails
  • 1,763
  • 4
  • 19
  • 36
0
votes
1 answer

Rails Grape API include module - Zeitwerk::NameError - expected file to define constant, but didn't:

I want to make a small code refactor and extract client external client from gem to a separate module (it's use to connect to the DatoCMS API via gem 'dato'). My standard class, which works well, look…
mr_muscle
  • 2,536
  • 18
  • 61
0
votes
1 answer

RSpec undefined method `each' in call

In my Grape API I've got an endpoint which is responsible of receiving data from CMS webhook - it works well but below specs are failed: describe ::Webhooks::Cms::ReceiveWebhook, type: :request do subject(:call) { post endpoint, params: params,…
mr_muscle
  • 2,536
  • 18
  • 61
0
votes
1 answer

Active Storage issue when uploading a file using fixture_file_upload - Rspec

I have to test my Grape API request which furthermore calls a service, this service saves the broker_profile data. When I upload an image using fixture file upload it throws an error of
0
votes
2 answers

Serialize only specific attributes with ActiveModel and Grape API depending on action

In my Grape API the same model can be accessed by different controllers and endpoints. I need to serialize the same model for each of them, but not every attribute applies to all endpoints. I know there is the "filter" method, but this removes an…
fnllc
  • 3,047
  • 4
  • 25
  • 42
0
votes
1 answer

block in load_missing_constant': uninitialized constant API::V1::Users (NameError)

Im trying to set up api endpoints for my rails application and keep receiving this error my environment is Ruby 2.6 and Rails 5.2 and im using the 'grape' gem for the api here is the blog I followed to set it up.…
Joe Slack
  • 35
  • 1
  • 10
0
votes
1 answer

Testing custom validators presence in params in ruby grape API

I have a very simple grape-powered API. Lets say that it looks like this: class MyApi < Grape::API params do requires :name, type: String requires :id, type: Integer, positive_value: true end get '/' do # whatever... end end I…
user1105595
  • 591
  • 2
  • 8
  • 20