ctx #
Constants #
const err_code_ctx_key = context.Key('status_code')
used internally in router
fn error_route #
fn error_route(req &Req, mut res Resp)
fn get_error_status_code #
fn get_error_status_code(req &Req) int
type HandlerFunc #
type HandlerFunc = fn (req &Req, mut res Resp)
type MiddlewareFunc #
type MiddlewareFunc = fn (mut req Req, mut res Resp)
enum SameSite #
enum SameSite {
@none
strict
lax
}
struct Cookie #
struct Cookie {
pub mut:
name string
value string
expires time.Time
max_age int
domain string
path string
http_only bool
secure bool
same_site SameSite = .lax
}
struct FormData #
struct FormData {
pub mut:
filename string
content_type string
content []u8
}
struct Req #
struct Req {
pub mut:
body []u8
method string
path string
params map[string]string
headers map[string][]string
raw_query string
boundary string
ctx context.Context
}
Server request data
fn (Req) parse_files #
fn (req &Req) parse_files() !map[string][]FormData
parse_files parses the multipart/form-data
content-type
fn (Req) parse_form #
fn (req &Req) parse_form() !map[string]string
parse_form parses the body based on its provided content-type and returns the output of it. Supports application/x-www-form-urlencoded
and application/json
content types. Returns an error if the body is blank, the "Content-Type" header is not present, or the content type header is not supported.
fn (Req) parse_headers #
fn (mut req Req) parse_headers(raw_headers []string)
parse_headers parses and injects the raw_headers into the request struct. Used internally by the router.
fn (Req) parse_query #
fn (req &Req) parse_query() ?map[string]string
parse_query parses the raw query string from the request and returns a map of strings
struct Resp #
struct Resp {
pub mut:
body []u8
status_code int = 200
headers map[string][]string = ctx.default_headers
stopped bool
}
Server response data
fn (Resp) headers_bytes #
fn (res &Resp) headers_bytes() []u8
fn (Resp) permanent_redirect #
fn (mut res Resp) permanent_redirect(url string)
fn (Resp) redirect #
fn (mut res Resp) redirect(url string)
redirect writes a 301 response and redirects to the specified url or location
fn (Resp) send #
fn (mut res Resp) send(body string, status_code int)
send writes the body and status code to the response data.
fn (Resp) send_file #
fn (mut res Resp) send_file(filename string, status_code int)
send_file writes the contents of the file to the response data.
fn (Resp) send_html #
fn (mut res Resp) send_html(ht string, status_code int)
send_html writes the body to the response data as an HTML content
fn (Resp) send_json #
fn (mut res Resp) send_json[T](payload T, status_code int)
send_json is a generic function that encodes the payload and writes the JSON string to the response data.
fn (Resp) send_status #
fn (mut res Resp) send_status(status_code int)
send_status sends an HTML response of the status code
fn (Resp) stop #
fn (mut res Resp) stop()
stop terminates the response