Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 15 21:12
    grape-bot commented #1943
  • Dec 15 21:11
    ericproulx synchronize #1943
  • Dec 15 19:46
    ericproulx synchronize #1943
  • Dec 15 19:32
    dblock commented #1944
  • Dec 15 19:32

    dblock on master

    AttributeTranslator optimizatio… (compare)

  • Dec 15 19:32
    dblock closed #1944
  • Dec 15 19:27
    grape-bot commented #1943
  • Dec 15 19:22
    ericproulx synchronize #1943
  • Dec 15 19:22
    grape-bot commented #1944
  • Dec 15 19:21
    ericproulx synchronize #1944
  • Dec 15 18:01
    dblock commented #1944
  • Dec 14 22:27
    grape-bot commented #1944
  • Dec 14 22:22
    ericproulx synchronize #1944
  • Dec 14 22:21
    ericproulx opened #1944
  • Dec 14 21:13
    grape-bot commented #1943
  • Dec 14 21:09
    ericproulx synchronize #1943
  • Dec 14 21:08
    grape-bot commented #1943
  • Dec 14 21:07
    ericproulx synchronize #1943
  • Dec 14 21:01
    grape-bot commented #1943
  • Dec 14 21:00
    ericproulx synchronize #1943
Jonathan Pares
@jonathanpa
ruby-grape/grape-entity#266
Jonathan Pares
@jonathanpa
Hi all
How do you handle the accepts_nested_attributes_for with Grape ?
Do you expect the nested_attributes format defined by rails in your params ?
or you try to use arrays of hash ?
Ryan Romanchuk
@rromanchuk
Does anyone have an elegant way to get a lograge key/value, single line, logging formatter with the fewest line of codes
grape's logging drives me nuts
Ivan Shamatov
@IvanShamatov
why don’t you use lograge as grape logger?
module API
  module Helpers
    module Logger
      extend ActiveSupport::Concern

      included do
        logger.extend(Xyeger::Logger)
        formatter =
          if Rails.env.production?
            Xyeger::Formatters::Json.new
          else
            Xyeger::Formatters::Values.new(
              colored: true,
              except: %i[hostname pid app env level]
            )
          end

        use GrapeLogging::Middleware::RequestLogger,
          formatter: formatter,
          include: [
            GrapeLogging::Loggers::Response.new,
            GrapeLogging::Loggers::FilterParameters.new,
            GrapeLogging::Loggers::ClientEnv.new
          ]
      end
    end
  end
end
as an example
not lograge
Ryan Romanchuk
@rromanchuk
Thanks going to give it a try
anyone know how i can use grape's represent method with a roar module to pass a custom variable down, been RTFMing for a while and just don't see anything
i need to be able to access current_user in a roar template
Kasper Holbek Jensen
@kholbekj
Hey, I'm trying to write a DSL method for a custom versioning scheme, but I'm a bit confused about passing info to inside the endpoint. Say i have
module Grape
  module DSL
    module Configuration
      extend ActiveSupport::Concern
      module ClassMethods
        def version_list(versions)
          method_that_passes_stuff(versions: versions)
        end
      end
    end
  end
end

module API
  module V1
    class Example < Grape::API
    version_list([1,2,3])
    get "/" do
      versions = method_that_retrieves_stuff(:versions)
    end
  end
end
Alex
@snowcat-alex
Hello there! I am curious: what is the most idiomatic means to share code between resources? Is this pattern supported? I have many resources with similar methods and I would like to avoid repetition and simply express how they differ from a base resource "class".
Alex
@snowcat-alex
Perhaps this indicates I need to think about restructuring the API itself!
Anton Yordanov
@anton-yordanov
Hello everyone,
I'm building Rack Grape API and I'm wondering which is the best practice for code reloading in development.
Into the Grape docs there is recommendation to use grape-reload gem for that. But it seems to be a little bit outdated, because the latest commit is from Apr 9, 2015.
Can you share how you solve the code reloading ?
Sridhar B.S
@sriddbs_twitter
Hello people
I am using Grape API and devise gem as well in my application. How do I use devise within Grape API?? For example I want to register a user and I want to use devise to handle the registration but my API end point will be coming from Grape
Branko Arnaudovski
@brarnaudovski_gitlab
Hi all. I am trying to access the grape env params from Doorkeeper.configure block, to set up the resource_owner_authenticator. In the code I am storing the token from a custom Authenticator class to a env['auth_token']. But this env['auth_token'] is nil in the Doorkeeper.configure block. Any help on how to access this token?
Arda Karaduman
@c0ze

@sriddbs_twitter

previously I did something like this. create something like

        desc "login user"
        params do
          requires :email, type: String
          requires :password, type: String
        end
        post "/login" do
        # do your devise stuff here
        end

depending on where you mount this api, you can access it like

    POST       /v4/users/login(.json)
Arda Karaduman
@c0ze
@brarnaudovski_gitlab I am little bit unsure as to what you are trying to do, but could it be that the custom Authenticator class you have is not being instantiated when Doorkeeper.configure block is run ? Can you try making sure it is being loaded before Doorkeeper ? Just a guess.
Franklin Yu
@FranklinYu
Any help for ActiveRecord? I read the section https://github.com/ruby-grape/grape#activerecord-without-rails
Franklin Yu
@FranklinYu
The constant ActiveRecord::ConnectionAdapters::ConnectionManagement is not found. Is there any require to load it?
Franklin Yu
@FranklinYu
Anyone here? This room is not very active?
Peter Lauck
@griest_gitlab
does anyone know why grape route helpers are not available inside endpoints?
Ken Spencer
@IotaSpencer
Why am I getting a '405 Method Not Allowed' for a get request, I'm trying to do something close to
resource 'webhook' do 
  get ':hook_name' do
    project = SiteHook::Config.projects.find_project(params[:hook_name])
  end
end
dm1try
@dm1try
it means that the method being used by the client is not GET
maybe POST, you should check the logs
github uses POST their web-hooks, for example
Ken Spencer
@IotaSpencer
right, but I'm literally going to it in my browser and that's what it returns
@dm1try
http://127.0.0.1:9090/v1/webhook/iotaspencer.me.json
{"error":"405 Not Allowed"}
    resource do
      post '/webhook' do
        halt 403
      end
      resource '/webhook/' do
        get ':hook_name' do
          project = SiteHook::Config.projects.find_project(params[:hook_name])
          if project.nil?
            {message: 'project not found or private', status: 1}
          else
            {project: project}
          end
        end
      end
Ken Spencer
@IotaSpencer
Puma starting in single mode...
* Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://127.0.0.1:9090
Use Ctrl-C to stop
[2019-03-11 20:57:00 -0400] 127.0.0.1 - GET /webhook/iotaspencer.me.json
Exception `Grape::Exceptions::MethodNotAllowed' at /home/ken/everygit/site_hook/vendor/bundle/ruby/2.5.0/gems/grape-1.2.3/lib/grape/endpoint.rb:254 - Grape::Exceptions::MethodNotAllowed
dm1try
@dm1try
@IotaSpencer not reproducible on my side, feel free to create an issue
also you can check Allow response header, as described here https://github.com/ruby-grape/grape#allowed-methods
Ken Spencer
@IotaSpencer
is there a reason why i can't use a . in my route param eg /webhook/iotaspencer.me/
With the way I have my code and had my code before when i was using sinatra I could use /webhook/iotaspencer.me/ yet now with grape i can't seem to use it, I can only use the 'more valid' and final format i've chosen for how they are implemented internally, which is basically by taking any non valid url character and changing or removing them, so like spaces and . in project name and in the webhook call, are internally _
Ken Spencer
@IotaSpencer
meaning that yes, 'iotaspencer.me' and 'iotaspencer me' are the same project internally and as such would be validated as duplicate projects
Nitesh Sharma
@sinscary

Hi,
We have been using grape for a long time and thanks for such a great framework.

Below is how we set values for a param.

params do
        optional :my_column1, type: Integer, desc: 'some description', values: MyModel1.all.pluck(:id)
        optional :my_column2, type: Integer, desc: 'some description', values: MyModel2.all.pluck(:id)
end

Our database is shared between two services. The above two columns(my_column1 and my_column2) get updated by other microservice. And when someone makes a request using API, it fails with the error message "my_column1 does not have a valid value.". same goes for my_column2.

While debugging I realized that during booting of rails application these values are being set and it only gets updated when we restart the server next time.

What we want are these values to be updated dynamically. Which means every time we make a request, it should make a query to the database and set those values. I am having a very hard time figuring out how to do this, or even if it's possible with Grape.

Any help will be appreciated.

Kevin Elliott
@kevinelliott
Hey guys. I’ve got an endpoint that is loading a significant number of records (~15k) and then running them through the formatter. It’s bloating memory significantly (500-700MB per request) and causing big problems for us. Unfortunately NewRelic instrumentation doesn’t help us much (just clumps to Proc#call). The obvious fix is to add pagination and for the internal client to use pagination, but that’s not within our power at the moment. The endpoint is only building up an AR scope, then formatting the collection to JSON — no real magic here, no complex logic. What can I do to minimize (or even better, eliminate) this memory bloat?
matrixbot
@matrixbot
Peter Lauck
@griest_gitlab
options[:env] doesn't seem to always be available in grape entity, anyone know why?
I think its only available in root-level exposures, i.e. when I use present in my endpoints
Anton Yordanov
@anton-yordanov
@sinscary try with values: -> { MyModel1.all.pluck(:id) }
Paulo Daniel Carneiro
@PauloDanielCarneiro
Hello people.
Quick question.
Is there any way to debug a grape API?