class Athena::Routing::RedirectResponse
- Athena::Routing::RedirectResponse
- Athena::Routing::Response
- Reference
- Object
Overview
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 < ART::Controller
@[ART::Get(path: "/go_to_crystal")]
def redirect_to_crystal : ART::RedirectResponse
ART::RedirectResponse.new "https://crystal-lang.org"
end
end
ART.run
# GET /go_to_crystal # => (redirected to https://crystal-lang.org)
Defined in:
redirect_response.crConstructors
-
.new(url : String, status : HTTP::Status | Int32 = HTTP::Status::FOUND, headers : HTTP::Headers = HTTP::Headers.new)
Creates a response that should redirect to the provided url with the provided status, defaults to 302.
Instance Method Summary
-
#url : String
The url that the request will be redirected to.
Instance methods inherited from class Athena::Routing::Response
content : String
content,
content=(content : String | Nil)
content=,
headers : HTTP::Headers
headers,
status : HTTP::Status
status,
status=(code : HTTP::Status | Int32) : Nil
status=,
write(output : IO) : Nil
write,
writer=(writer : ART::Response::Writer)
writer=
Constructor methods inherited from class Athena::Routing::Response
new(status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new, &block : IO -> Nil) : ART::StreamedResponsenew(content : String | Nil = nil, status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new) new
Constructor Detail
def self.new(url : String, status : HTTP::Status | Int32 = HTTP::Status::FOUND, headers : HTTP::Headers = HTTP::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.