-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Hi,
We'd like to build an API that is able to paginate entities and send them in chunks.
A really raw way of sending data in chunks would be:
require 'grape'
module Stream
class API < Grape::API
prefix 'api'
format :txt
default_format :txt
class Streamer
def initialize(pages:, page_size:, latency:)
@pages = pages
@page_size = page_size
@latency = latency
end
def each
(1..@pages).lazy.each do |p|
yield "#{p}\n" * @page_size
sleep(@latency)
end
end
end
resources :users do
params do
optional :pages, type: Integer, default: 10
optional :page_size, type: Integer, default: 10
optional :latency, type: Float, default: 1.0
end
get do
status 200
p = declared(params)
stream Streamer.new(pages: p.pages, page_size: p.page_size, latency: p.latency)
end
end
end
end
With this approach I get the deprecation warning:
[DEPRECATION] Argument as FileStreamer-like object is deprecated. Use path to file instead.
because Grape assumes the response is a file.
Will you support streaming of a Grape::Entity
or any other non-file objects in the future?
dmitry and mikdiet