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

Ruby Grape Api multiple routes with single method

I want to accept multiple routes in a single method. resource :mypath do helpers do def mymethod super_duper_stuff end end post do something_else end get do mymethod end resource :subpath post do …
user433342
  • 859
  • 1
  • 7
  • 26
2
votes
1 answer

Share desc and type across Grape and Grape Entity gems

What I'm trying to do is to reuse type and description across grape and grape-entity gems. In the documentation I read the following: You can use entity documentation directly in the params block with using: Entity.documentation. module API …
Francesco Meli
  • 2,484
  • 2
  • 21
  • 52
2
votes
1 answer

Create dynamically named class within module namespace

I'm working with a Grape API and I have models which have a url attribute that I'm using to dynamically mount endpoints for. I need to be able to version them and I'm having trouble getting them to be properly namespaced when they're generated. If…
Joshua Hunter
  • 4,248
  • 2
  • 12
  • 13
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

How to properly test a 'post' (create) method in Ruby on Rails with Grape and MongoDB

I'm having an issue when attempting to test one of my POST API calls which creates a new user: class API::V1::Users::APITest < ActiveSupport::TestCase include Rack::Test::Methods def app Rails.application end test 'POST /api/v1/users…
the_basterd
  • 623
  • 1
  • 5
  • 9
2
votes
2 answers

How to add common header in Rails with Grape?

Is there any way that I can common header in Rails with Grape so I do not have to specify the same header over and over again? namespace :user do desc 'Return a user.', { headers: { "Authorization" => { description: "Some…
user3019766
  • 131
  • 1
  • 10
2
votes
1 answer

Rails: how to make url with multi slash in Grape

I'm using grape for restful service. As I know, :resource will define a path in url. For example: module Sample module V1 module Order class GetCheckInListApi < ApplicationApi resource :check_in_list do get root: :data…
Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107
2
votes
0 answers

Rails API with Grape, polymorphic: true, touch: true is not working

I am developing a Rails 4.2.6 API app with a number of polymorphic associations, the problem is touch: true does not show the updated object. class Post < ActiveRecord::Base belongs_to :postable, polymorphic: true, touch: true end class Event <…
2
votes
1 answer

Grape-Swagger: Route Parameter issues

I am using grape-swagger to show documentation on my Ruby API i'm building using Grape. I am adding descriptions to all of my parameters on my endpoints but I can't seem to find anything about how to add descriptions to route parameters. I have…
2
votes
1 answer

API endpoint not showing in swagger ui but is reachable

I have a grape swagger ui running in a docker compose project. the app builds and is browseable. the problem I have is I create a new API with the Napa generator (people in this case) and it does not show up in the swagger ui. I can log into the…
Nungster
  • 726
  • 8
  • 28
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

How do I change camelcase to snakecase in Grape params

In my Grape endpoint I have a required param called user_type. On the other hand, my public API declares this param as userType, i.e. camel case. Is there a way to changes this? module MyAPI module V1 class SignUp < Grape::API …
user468311
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
2 answers

Grape API (swagger doc) - Global configuration of 'desc'

Its been an interesting an busy week. I am working on a Rails project and included Grape to implement the API. The API has 2 sections No auth required (no headers) Auth required I setup the app with and all is working... Grape Grape Swagger Grape…
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71