ActionController::Responders
Constants
common response mime types
codes to use when redirecting
standard response codes
Class methods
A String is already the complete response body. Crystal's HTTP response switches to chunked transfer when a write reaches its output buffer size; supplying the known length avoids that work for large bodies. Leave custom output wrappers and explicit framing headers in control of their own bytes.
Instance methods
Extracts the mime types from the Accept header
Scanned by hand rather than split(";").flat_map(&.split(ACCEPT_SEPARATOR_REGEX)...).
Every route that negotiates a content type runs this on every request, and
the regex plus the intermediate arrays it built dominated the cost.
Behaviour is unchanged, including that only a comma consumes the whitespace
that follows it.
Macros
only sends the header, no content to be sent.
you should only use render with the Macro DSL
delete "/:id", :destroy do
MyModel.find(route_params["id"]).destroy
head HTTP::Status::ACCEPTED
end
redirects the browser to a new route
you should only use render with the Macro DSL
patch "/:id", :update do
redirect_to "/#{params["id"]}"
end
used to stream a response back to the user, serializing directly to the IO
the content type is set appropriately based on the response type
a call to render implicitly executes a return as the response has been written to the client
you should only use render with the Macro DSL
get "/:id", :show do
render json: MyModel.find(route_params["id"])
end
uses the content-type header to respond in the appropriate format
you should only use render with the Macro DSL
get "/:id", :show do
model = MyModel.find(route_params["id"])
respond_with do
text model # calls to_s(response) on the object passed
json model # calls to_json(response) on the object passed
xml do # can provide a block to perform additional processing too
str = "<set_var>#{model.build_xml}</set_var>"
XML.parse(str)
end
end
end