Module restia.request

A helper “object” that provides common request-related information as attributes.

Most functions are either reasonably fast or memoized, so the user does not need to take care of caching values outside of very critical code.

Usage:

    local req = restia.request
    -- restia.controller.xpcall passes this as its first argument automatically
    if req.method == "GET" then
    	ngx.say(json.encode({message="Greetings from "..params.host.."!"}))
    else
    	ngx.say(json.encode(req.params))
    end
    

Info:

  • License: Unlicense
  • Author: DarkWiiPlayer

Functions

offer (available, ...) “Offers” a set of content types during content negotiation.
offer_type (...) “Offers” a set of content types during content negotiation.

Getters

params () Returns the request parameters.
method () Returns the HTTP method of the current request.
headers () Returns a table containing all headers.
type () An alias for headers.content_type.
host () Returns the current hostname or address.
path () Returns the path part of the current request URI
cookie () Wraps the lua-resty-cookie module and returns a cookie object for the current request.


Functions

offer (available, ...)
“Offers” a set of content types during content negotiation. Given a set of possible content types, it tries figuring out what the client wants and picks the most fitting content handler. Automatically runs the handler and sends the result to the client. For the most part, this is a wrapper around restia.negotiator.pick and follows the same semantics in its “available” argument. When no content-type matches, an error is raised.

Parameters:

  • available table A map from content-types to handlers. Either as a plain key-value map or as a sequence of key-value pairs in the form of two-element sequences.
  • ... Additional arguments to be passed to the content handlers
offer_type (...)
“Offers” a set of content types during content negotiation. Instead of picking an associated handler, this function simply returns the chosen content-type to be handled by the application. When no content-type matches, it returns nil and an error message.

Parameters:

  • ...

Getters

params ()
Returns the request parameters.

Returns:

    table A table containing the request parameters.
method ()
Returns the HTTP method of the current request.

Returns:

    string Method The request method
headers ()
Returns a table containing all headers. For missing headers, it tries replacing underscores with dashes.

Returns:

    table Headers
type ()
An alias for headers.content_type.

Returns:

    string Content type header
host ()
Returns the current hostname or address.

Returns:

    string Hostname or Address
path ()
Returns the path part of the current request URI

Returns:

    string Path part of the URI
cookie ()
Wraps the lua-resty-cookie module and returns a cookie object for the current request.

Returns:

    Cookie object
generated by LDoc 1.4.6 Last updated 2021-01-03 16:45:09