Title: Reply Builder (aka Response Builder) Desc: Framework provides Reply builder to compose your response effectively. You can do Chained call. Keywords: reply builder, reply, response, html, json, jsonp, text, bytes, file, status code, cookie, redirect
Framework provides Reply
builder to compose your response effectively. You can do Chained call.
- Response Status Codes
- Response Content
- Redirect
- Replying HTTP Headers
- Cookie
- Disable Gzip
- Done()
- Sample
As per RFC7231, provides method for frequently used ones.
Ok()
Created()
Accepted()
NoContent()
MovedPermanently()
Found()
TemporaryRedirect()
BadRequest()
Unauthorized()
Forbidden()
NotFound()
MethodNotAllowed()
Conflict()
InternalServerError()
ServiceUnavailable()
ohh, I do not find status method, just use Reply().Status(http.StatusPartialContent)
or Reply().Status(206)
Rich reply methods for the response.
HTML(data)
HTMLl(layout, data)
HTMLf(filename, data)
HTMLlf(layout, filename, data)
JSON(data)
JSONP(data, callback)
XML(data)
Text(str)
Text(str, args)
Readfrom(reader)
File(file)
FileDownload(file, targetName)
- Content-Disposition is attachmentFileInline(file, targetName)
- Content-Disposition is inlineBinary(bytes)
Redirect(url)
RedirectSts(url, statusCode)
Header(hdr, value)
HeaderAppend(hdr, value)
Cookie(cookie)
DisableGzip
method provides an option to disable gzip
compression for a particular response.
Reply().DisableGzip()
Done method indicates to framework that reply has already been sent via aah.Context.Res
and that no further action is needed.
Note: Framework doesn't intervene with response if Done()
method is called.
// Replying JSON with status 200
// Default status code is 200
c.Reply().Ok().JSON(data)
// OR
c.Reply().JSON(data)
// Replying file as an attachment
c.Reply().FileDownload("/User/jeeva/songs/nice.mp3", "name-nice.mp3") // default status code is 200 OK
// Replying redirect login page using `route name`
c.Reply().Redirect(c.ReverseURL("user_login"))
// Replying HTML response with cookie and view arguments
c.Reply().
Cookie(&http.Cookie{
//....
}).
HTML(data)
// Replying HTML response with custom layout and data
c.Reply().HTMLl("master-docs.html", data)