You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
Similar to the example, I have setup rack-stream requiring the lib and adding "use Rack::Stream" to my config.ru. I'm using rackup but I have some issues getting the DSL methods to work:
class:API': undefined method `after_open' for #Grape::Endpoint:0x0000010142b218 (NoMethodError)
Ans using stream:
class:API': undefined method `stream' for #Grape::Endpoint:0x000001022bfe78 (NoMethodError)
Any idea whether I'm missing something here ?
In my API class I do something like:
class API < Grape::API
format :json
prefix 'api'
version 'v1'
include Rack::Stream::DSL
resource :messages do
post do
#does stuff
end
get do
after_open do
chunk my_data_method
end
status 200
header 'Content-Type', 'application/json'
chunk 'bye!'
""
end
end
end
The text was updated successfully, but these errors were encountered:
Thanks - Actually my app changed a bit and I'm calling a @data.get_stuff method inside the "get do". Data is an object that handles the SQL bit and the long polling waiting. I have tried to include or extend the module Rack::Stream::DSL from this other class Data, but still have no success in finding the DSL methods there ?
Ok I made some progress. I managed to pass the env to the method in the other class as a parameter and I can call env['rack.stream'].chunk or env['rack.stream'].close directly from there.
A small issue I have now is when calling:
env['rack.stream'].chunk 'nothing to say'
In the actual body response the content is something like <Rack::App...>nothing to say
Returning "" at the end of the get do method the response body is set to: ""nothing to say, which is still not ideal. Any idea how to avoid returning anything from there?
Another question I have is, do I have to set status/headers as in the example? Previously Grape would handle this for you.
Another update on this. I managed to get it working. I realised in the example the default_format in Grape is set to :txt, but then manually set to json using the headers. That worked, as using text seems to merge that final "" while in JSON it expects a JSON object and returning back something like {} will get merged into an array in the body.
Anyway, I do see this as a workaround and perhaps a better solution would be to somehow override the Grape method that process the body - possibly not easy to do.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
Similar to the example, I have setup rack-stream requiring the lib and adding "use Rack::Stream" to my config.ru. I'm using rackup but I have some issues getting the DSL methods to work:
class:API': undefined method `after_open' for #Grape::Endpoint:0x0000010142b218 (NoMethodError)
Ans using stream:
class:API': undefined method `stream' for #Grape::Endpoint:0x000001022bfe78 (NoMethodError)
Any idea whether I'm missing something here ?
In my API class I do something like:
The text was updated successfully, but these errors were encountered: