Return Different Formats
JSON Response
struct JsonEndpoint
include Azu::Endpoint(EmptyRequest, Azu::Response::Json)
get "/api/data"
def call
json({
message: "Hello",
timestamp: Time.utc.to_rfc3339
})
end
endCustom JSON Response
struct UserResponse
include Azu::Response
def initialize(@user : User)
end
def render
{
id: @user.id,
name: @user.name,
email: @user.email
}.to_json
end
endText Response
HTML Response
Using Templates
Empty Response
Content Negotiation
Setting Headers
Redirect Response
File Download
See Also
Last updated
Was this helpful?
