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
3
votes
2 answers

Send file to a client using Grape API

I have been doing rails application that used carrierwave for file uploads. How can I send existing file to a client using Grape API? Let's assume that file is in directory "public/uploads/datafile/1/file.txt".
Prostakov
  • 910
  • 1
  • 12
  • 22
3
votes
1 answer

Grape API modify parameter presence error

As you know, you can specify that a parameter is required in a route like so: requires :province, :type => String However, I would like to be able to change the error that is thrown and provide my own error JSON when the parameter is not given. How…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
3
votes
1 answer

Split Grape API (non-Rails) into different files

I am writing an API in Grape, but it stands alone, with no Rails or Sinatra or anything. I'd like to split the app.rb file into separate files. I have looked at How to split things up in a grape api app?, but that is with Rails. I'm not sure how to…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
3
votes
1 answer

Add Path / Auto Load Path For Grape API Not Working

I am using Grape to build my API, and according to the documentation, I added the following lines to application.rb so that allapp/api` ruby scripts are added to the path, as well as allowing auto-reload for development mode: config.paths.add…
darksky
  • 20,411
  • 61
  • 165
  • 254
3
votes
1 answer

Mount Grape / Sinatra API in Rails on subdomain

My Rails 3 app is using Grape API. I know how to mount that API on a selected route mount API => '/api' but I need that api to be accessible on subdomain api.mydomain.com. I searched Grape & Sinatra docs, questions on stack overflow and tried to…
Marek Takac
  • 3,002
  • 25
  • 30
3
votes
2 answers

Loading attributes only once in Grape

I'm little new to Ruby, but I have the following coded using Grape API in Ruby. I have @data = YAML.load() called every time it hits GET /api/v1/foo, is there a way in Grape to only load it once and use it? This way is more optimized and not…
samxiao
  • 2,587
  • 5
  • 38
  • 59
3
votes
1 answer

What are the benefits of using Grape in the Rails app?

I have a Rails web app and I want to provide API. I have found Grape and it looked nice and it can also be mounted into Rails but I am not sure of benefits of mounting Grape into my Rails app and use it for API instead of Rails controllers. As I…
Tomáš Linhart
  • 13,509
  • 5
  • 51
  • 54
2
votes
1 answer

I got 'Document is empty' when using grape

all I got the error when using grape. This page contains the following errors: error on line 1 at column 1: Document is empty Below is a rendering of the page up to the first error. in fact, My api works and return the xml well. and after…
dexterdeng
  • 249
  • 3
  • 13
2
votes
0 answers

Grape Swagger Description from File

I am writing an API with Grape mounted in a Ruby on Rails 5.2 application. I do have some extended API notes in markdown files that I would like to use directly in the desc block for the description. I currently load the markdown as follows: module…
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
2
votes
1 answer

Rails Fast Json API includes scope

In my Rails 6/Grape API app I've got a serializer where I want to include only active journeys (by active I mean journey.is_deleted: false). Current endpoint looks like: helpers do def query …
mr_muscle
  • 2,536
  • 18
  • 61
2
votes
1 answer

Rspec GET to a different endpoint for a second - ActionController::UrlGenerationError

In my Grape/Rails app I've implement maintenance mode in ApplicationController so when this mode is active it will redirect to the maintenance_mode_path from anywhere in the app. How to force rspec to be in a different endpoint for a while eg.…
mr_muscle
  • 2,536
  • 18
  • 61
2
votes
1 answer

Rspec mock ActiveRecord::Relation instead of class object

I want to mock one line from my endpoint: InquiryProcessFilters::CompanyName.new(params[:filters][:company_name].downcase).call So I've mock: let(:company_name_filter_mock) { instance_double(InquiryProcessFilters::CompanyName) } before do …
mr_muscle
  • 2,536
  • 18
  • 61
2
votes
2 answers

Combining multiple objects in an array for json using Grape

I'm using the grape gem in my rails application. When returning a single record I can use the grape active model serializer. When returning multiple objects I run into an undefined error. How should I structure my multiple campaign records?…
2
votes
1 answer

grape-api - Force empty string to set values to null

I am creating an API endpoint which contains a file upload field and a few string fields. My goal is to allow clients to clear values on those string fields, i.e. the DB should persist these values as null. However, due to the fact that the request…
Martin Verdejo
  • 1,229
  • 2
  • 13
  • 24
2
votes
0 answers

How to use before_action methods of Pundit in rails grape api

I'm mounting Grape in my Rails project to build a RESTful API. Web applications application controller runs verify_authorized after every action. class ApplicationController < ActionController::Base include Pundit protect_from_forgery with:…
Akash Kinwad
  • 704
  • 2
  • 7
  • 22