class Athena::Routing::StreamedResponse
- Athena::Routing::StreamedResponse
- Athena::Routing::Response
- Reference
- Object
Overview
Represents an ART::Response
whose content should be streamed to the client as opposed to being written all at once.
This can be useful in cases where the response content is too large to fit into memory.
The content is stored in a proc that gets called when self
is being written to the response IO.
How the output gets written can be customized via an ART::Response::Writer
.
Defined in:
streamed_response.crConstructors
-
.new(status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new, &block : IO -> Nil)
Creates a new response with optional status, and headers arguments.
-
.new(callback : Proc(IO, Nil), status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new)
Creates a new response with the provided callback and optional status, and headers arguments.
Instance Method Summary
-
#content=(callback : Proc(IO, Nil))
Updates the callback of
self
.
Instance methods inherited from class Athena::Routing::Response
content : String
content,
content=(content : String | Nil)
content=,
etag : String | Nil
etag,
headers : HTTP::Headers
headers,
last_modified : Time | Nil
last_modified,
last_modified=(time : Time | Nil = nil) : Nil
last_modified=,
send(context : HTTP::Server::Context) : Nil
send,
set_etag(etag : String | Nil = nil, weak : Bool = false) : Nil
set_etag,
set_public : Nil
set_public,
status : HTTP::Status
status,
status=(code : HTTP::Status | Int32) : Nil
status=,
writer=(writer : ART::Response::Writer)
writer=
Constructor methods inherited from class Athena::Routing::Response
new(content : String | Nil = nil, status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new)
new
Constructor Detail
Creates a new response with optional status, and headers arguments.
The block is captured and called when self
is being written to the response's IO
.
This can be useful to reduce memory overhead when needing to return large responses.
require "athena"
class ExampleController < ART::Controller
@[ARTA::Get("/users")]
def users : ART::Response
ART::StreamedResponse.new headers: HTTP::Headers{"content-type" => "application/json; charset=UTF-8"} do |io|
User.all.to_json io
end
end
end
ART.run
# GET /users # => [{"id":1,...},...]
Creates a new response with the provided callback and optional status, and headers arguments.
The proc is called when self
is being written to the response's IO
.