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
60
votes
4 answers

What is the difference between `try` and `&.` (safe navigation operator) in Ruby

Here is my code: class Order < Grape::Entity expose :id { |order, options| order.id.obfuscate } expose :time_left_to_review do |order, options| byebug order&.time_left_to_review # ERROR end expose :created_at { |order, options|…
Adrien
  • 2,088
  • 1
  • 18
  • 35
19
votes
1 answer

What should the Content-Type be for a 4xx error without a body?

Consider an HTTP request that gets the following response: 405 Method Not Allowed Content-Length: 0 What should the content-type of something like this be? Set to nothing? Not set? Set to text/plain or text/html
dB.
  • 4,700
  • 2
  • 46
  • 51
14
votes
2 answers

How to split things up in a grape api app?

In every examples I see, people only implement one giant api.rb file. Ex: intridea/grape bloudraak/grape-sample-blog-api djones/grape-goliath-example While this approach works fine as is, it can quickly become crowded and difficult to maintain so…
X2theZ
  • 278
  • 4
  • 16
12
votes
3 answers

{grape} authorization

I'm attempting to create a restful, json api in ruby - so I'm using grape (https://github.com/intridea/grape) inside of Rack. I'm not using Rails for this project, so cancan, sorcery, etc... don't seem to be the best options. Plus, I'd hate to mix…
Josh
  • 6,155
  • 2
  • 22
  • 26
11
votes
6 answers

Accessing compiled routes in Grape / Rack::Mount::Route

I'm trying to generate a list of all routes generated by my subclass of Grape::API (MyApi). I can get close by calling: MyApi.send(:route_set).instance_variable_get(:@routes) which gives me an array of Rack::Mount::Route objects. The only attribute…
Josh
  • 621
  • 6
  • 10
10
votes
1 answer

Mixed Content error nginx ingress in kubernetes for rails app

Deploying Portus in GCP with an Nginx Ingress load balancer implemented. Portus loads up just fine but when trying to use the application and fill out some of the forms I get the following error: VM798:1 Mixed Content: The page at …
niharvey
  • 2,807
  • 2
  • 15
  • 24
10
votes
3 answers

How to handle before filter for specific action in Grape?

I'm mounting Grape in my Rails project to build a RESTful API. Now some end-points have actions need authentication and others which don't need authentication. As for example I have users end-point which looks something like: module Backend …
Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81
10
votes
2 answers

How to allow Binary File download using GRAPE API

I want to allow downloading a binary file (.p12 file) using ruby's Grape API. This is what I am trying. get '/download_file' do pkcs12 = generate_pkcsfile content_type('application/octet-stream') body(pkcs12.der) end The equivalent code…
boboverflow
  • 309
  • 4
  • 10
9
votes
2 answers

how to get the remote ip (requester) on grape-api rails application

I have a working rails application with grape-gem working as an end point for some APIs in the application. I need to get the remote ip for the requester and return it back in the response. I could do that on regular controllers…
alybadawy
  • 489
  • 2
  • 7
  • 13
9
votes
1 answer

Sinatra and Grape API together?

I've been reading around and I found this micro-framework called Grape for ruby. I am currently using Sinatra to handle the web interface but I would also like to implement Grape to handle the API aspect of the app. I can't find any helpful…
Cristian Rivera
  • 187
  • 1
  • 5
8
votes
1 answer

grape each entity in a single file

I want to have multiple classes inside grape entity file, this is the folder structure app/api/proj/api/v2/entities/committees.rb module PROJ::API::V2::Entities class Committee < Grape::Entity expose :id expose :name, :full_name, :email, :tag,…
Anbazhagan p
  • 943
  • 1
  • 14
  • 27
8
votes
1 answer

Why use helpers in a Grape API versus including a module?

When writing an API with Grape, why bother using the helpers macro, versus just including a module, or adding a method? For example, you can define methods in a module and include them as helpers in Grape like so: module HelperMethods def…
huntmaster
  • 258
  • 1
  • 3
  • 10
8
votes
2 answers

How to define array of hashes in Grape?

I'm using Ember as my front-end and Grape API to serve my API. The front-end send something like: { "service"=>{ "name"=>"Name", "duration"=>"30", "user"=>nil, "organization"=>"org", "category"=>nil, …
Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81
8
votes
2 answers

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '',…
Rupali
  • 311
  • 3
  • 5
8
votes
1 answer

Can't understand Grape API route param

I am having a lot of trouble understanding Grape API, specifically route_param and how it works with just params. Consider this code: desc "Return a status." params do requires :id, type: Integer, desc: "Status id." end route_param :id do get do …
kcg5544
  • 203
  • 3
  • 5
1
2 3
20 21