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

How to show parameters of Grape API when it is hash or array and the inside value isn't defined with swagger doc

I am using swagger doc to generate API document in grape api. API parameters are defined like: desc "Get results by query" params do requires :type, type: String, desc: "search type" requires :body, type: Hash, desc: "query body" …
李梦驰
  • 59
  • 3
2
votes
1 answer

Grape API: code in parent class of GRAPE::API not work

I'm using grape api. I also use graph logger library for logging all requests from client. I design a general class, because it will be used from many other places. require 'grape_logging' class GeneralGrapeApi < Grape::API logger.formatter =…
Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107
2
votes
1 answer

Ruby/Grape required parameters on a certain condition

For one of my methods the following isn't working. I pretty much copied everything straight out of the official documentation: params do requires :authenticationType, type: Array[String], values: ['LOCAL', 'AD'] given authenticationType: ->(val) {…
pirhac
  • 887
  • 2
  • 8
  • 16
2
votes
1 answer

SImplecov - Incorrect test coverage for Grape API

I have a Rails 4.2 app with an API based on Grape. I started to write tests for it using Rpsec. My tests work great and test what I expected. But when I run rspec at terminal, Simplecov is not showing the correct coverage for the api files, as you…
Fabiano Arruda
  • 648
  • 7
  • 21
2
votes
1 answer

Pass Parameters from Grape::API to Serializer

I am getting a parameter e.g: member_id in Grape::API like desc 'Return Events' params do requires :member_id, type: Integer, desc: 'Member' end get 'all' do #some code end …
Muhammad Faisal Iqbal
  • 1,796
  • 2
  • 20
  • 43
2
votes
1 answer

Capybara : Integration test for an API between two rails apps

We are currently developping two rails apps that communicates via an API (made with Grape). This morning I worked on the 'server' app, and the changes I made results in an error 5OO on the staging of the 'client' app. To adress that, I want to…
Ruff9
  • 1,163
  • 15
  • 34
2
votes
0 answers

Rails Swagger-UI can't read swagger JSON

I've been tried a lots ways, but I just stuck here. Grape API can do post and get perfectly, but the swagger-ui encountered some problems. I put swagger-ui in public folder, when I open it. It threw Can't read swagger JSON from…
rj487
  • 4,476
  • 6
  • 47
  • 88
2
votes
2 answers

Pundit policy_scope with Grape api

I am building API endpoints with Grape. I have below scope: class JourneyPolicy < ApplicationPolicy def create? user && user.identt_id == record end class Scope attr_reader :user, :scope def initialize(user, scope) @user =…
przbadu
  • 5,769
  • 5
  • 42
  • 67
2
votes
1 answer

Grape route with array as root object

I'm defining params for a grape route like this params do requires :array, type: Array do requires :foo, type: String requires :bar, type: String end end The data for this endpoint would be {"array": [{"foo":…
23tux
  • 14,104
  • 15
  • 88
  • 187
2
votes
1 answer

What should return the Grape rescue_from :all block?

The Grape documentation says that: The rescue_from block must return a Rack::Response object, call error! or re-raise an exception. but if we use the rescue_from method only to log things and we want to keep the original HTTP answer what should we…
Jules Ivanic
  • 1,579
  • 2
  • 15
  • 28
2
votes
1 answer

Deploy Grape API with Nginx/Passenger

I have Nginx and Passenger installed on my server. Trying to run a Grape (Rack) API off it. When I deploy Rails applications I have this server block in Nginx conf; server { listen 80; server_name yourserver.com; # Tell Nginx and…
Shakeeb Ahmad
  • 2,010
  • 1
  • 25
  • 30
2
votes
1 answer

Custom error with grape when using http_basic

Im using http_basic method in Grape in my rails app, I have got it working but would like to provide a custom error if the authentication details are incorrect. http_basic do |username, password| @project = Project.where(api_key:…
Sam Mason
  • 1,037
  • 1
  • 8
  • 29
2
votes
1 answer

Grape rescue Grape::Exceptions::ValidationErrors not working

I wrote an api to upload a image file to server. when I am upload without a file, it will be error I tried to rescue it like this: rescue_from Grape::Exceptions::ValidationErrors do |e| error! e.message, 404 end but it doesn't work. Here is…
Luan D
  • 1,320
  • 1
  • 13
  • 26
2
votes
1 answer

Grape - File Upload - Parameter declaration

I am writing my first API using Grape and am quite excited and it sounds and feels grate. Running through the notes I couldn't find a way to declare parameters for a file. Below is a work-in-progress class for providing profile details, updating…
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
2
votes
1 answer

Versioning Grape active_model_serializer

I'm trying to make a V2 api for my rails app with grape and grape_active_model_serializer. But I can't figure how to make a serializer for each version of my api. Here is what my api look like app/api/api.rb : require 'grape-swagger' class API <…