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

How to make all Time outputs be ISO 8601 in Ruby + Grape API

I've been looking around for the easiest solution to convert all Datetime values to ISO 8601 when sending them to a specific requester from an API. I was able to monkey patch Time#to_json with the following: class Time def to_json(options = {}) …
Maaack
  • 115
  • 10
3
votes
1 answer

Is it possible to give optional URL parameter in grape route

Is it possible to give optional URL parameter in grape route. Ie. for a an endpoint like : get '/user/:name/:location/:id' do end Is there any way to hit this endpoint with or without "location" parameter in the URL. I tried defining…
Hridya
  • 236
  • 2
  • 12
3
votes
1 answer

Wisper and Grape return results from a POST request

I have a simple POST Grape endpoint with Wisper pub/sub in a background: module Something class Doit < Grape::API post :now do service = SomePub.new service.subscribe(SomeSub.new) service.call(params) end end end Here…
There Are Four Lights
  • 1,406
  • 3
  • 19
  • 35
3
votes
1 answer

Grape custom error with status code

Hi I am working on rails project right now with Grape Basically I wanna make a custom error with grape since its supported. I have managed to create the custom error, something like this module API module ErrorFormatter def self.call(message,…
kilua
  • 711
  • 1
  • 9
  • 16
3
votes
2 answers

Grape get username:password from BasicAuth

I'm starting to build a really small API and I need to authenticate some endpoints, not all of them. I want to be able to select which endpoint to force authentication with an authenticate! method to be called in the body of the 'route'. For…
Andres
  • 11,439
  • 12
  • 48
  • 87
3
votes
1 answer

Passing argument to grape-entity modules

The requirements of my project are now forcing me to passing parameters to nested entities. I have an entity A and an entity B that show some information and needs the A identifier on the system to build them. module Services module Trips class…
3
votes
2 answers

Ember.js POST requests return 400 from the server (Grape API) but are stored successfully into local storage

I've been trying to get a simple Ember.js application to post to a Grape API backend for hours now, but I cannot seem to get it to work. I know the API works because I can post new records to it through the Swagger documentation, and they are…
3
votes
2 answers

Grape Swagger describe JSON body

I'm sending JSON request for most of the POST requests and I embed the JSON in the request body. How can I describe this using grape swagger ?
Jani
  • 1,400
  • 17
  • 36
3
votes
1 answer

Not understanding nested resources using the Grape API gem in Rails

Here is what my API looks like: module ServiceRequests class API < Grape::API version 'v1', using: :path format :json namespace :companies do params do requires :company_id, type: Integer, desc: "A Company Id" …
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
3
votes
1 answer

Resolve all ActiveRecord Associations using Grape::Entity (SQL Join)

Question I've been messing with ruby, grape, grape-entity, and activerecord. Everything is going swimmingly however I can't see to get the desired result from grape-entity when using the using keyword for a expose item. My goal is to basically…
abc123
  • 17,855
  • 7
  • 52
  • 82
3
votes
1 answer

Rails 4 Grape API ActionController::RoutingError

I am trying to make a Grape API answering in json format to all its verbs. The problem is that I can't make it answer to a routing error in json format. I even can't rescue the ActionController::RoutingError. I have read this link…
hector
  • 907
  • 1
  • 9
  • 23
3
votes
1 answer

Why is Ruby server spawning zombies only when daemonized?

tl;dr: rackup -p 1234 <= works. rackup -p 1234 -D <= creates zombies. Why? I'm running a Grape API server with supporting functions in a separate file. My aim is for the start of the server to create a long-running separate background process…
Sam
  • 1,205
  • 1
  • 21
  • 39
3
votes
2 answers

Multiple Route Params in Grape

How do you get multiple route params in Grape to work in grape? I can make this route work: .../api/company/:cid But when I try this: .../api/company/:cid/members .../api/company/:cid/members/:mid I get errors. Here's the code that works. resource…
gojohnnygo
  • 1,148
  • 1
  • 10
  • 13
3
votes
1 answer

Rack apps mounted in different subdomains

I'm building a Grape API alongside Sinatra. So far I've been mounting them in separate routes like this: run Rack::URLMap.new("/" => Frontend::Server.new, "/api" => API::Server.new) Where the "/api" is served by a Grape app and…
3
votes
1 answer

testing rails grape API with curl, params array

I am manually testing my rails application grape API using curl. I would like to send a [1,2,3] array as a request query parameter for to to be accesible like: p params[:tickets_ids] => [1,2,3] I only found clues how to send something what is…
pawurb
  • 516
  • 6
  • 19