class Athena::HTTP::RedirectResponse
inherits Athena::HTTP::Response
#
Represents an HTTP response that does a redirect.
Can be used as an easier way to handle redirects as well as providing type safety that a route should redirect.
require "athena"
class RedirectController < ATH::Controller
@[ARTA::Get(path: "/go_to_crystal")]
def redirect_to_crystal : AHTTP::RedirectResponse
AHTTP::RedirectResponse.new "https://crystal-lang.org"
end
end
ATH.run
# GET /go_to_crystal # => (redirected to https://crystal-lang.org)
Constructors#
.new(url : String | Path | URI, status : ::HTTP::Status | Int32 = ::HTTP::Status::FOUND, headers : ::HTTP::Headers | AHTTP::Response::Headers = AHTTP::Response::Headers.new)#
Creates a response that should redirect to the provided url with the provided status, defaults to 302.
An ArgumentError is raised if url is blank, or if status is not a valid redirection status code.