Request

ctx.Request provides access to all information received from the client during the current request.

Through this object it is possible to consult general information about the request, access the requested URL, read headers and cookies, obtain query parameters, work with forms and files, inspect the route decided by GOX and access the body of the request.

gox
func GET(ctx *gox.Context) gox.Page {

    method := ctx.Request.Method()
    path := ctx.Request.URL.Path()

    return <p>{{ method }} {{ path }}</p>
}

Basic information

In addition to its specialized properties, Request it sets out a number of methods for consulting general information on the current request.

MethodDescription
Method()Returns the HTTP method received.
IP()Returns the client's IP address resolved by GOX.
IsSecure()Indicates whether the request uses HTTPS.
ContentType()Returns the header value Content-Type.
gox
func GET(ctx *gox.Context) gox.Page {

    if ctx.Request.IsSecure() {

        return <span>HTTPS</span>
    }

    return <span>HTTP</span>
}

URL

ctx.Request.URL provides structured access to the request URL.

It allows to consult the schema, host, port, route, reference string and the rest of the URL components without having to manually analyze them.

See the full documentation at URL.


Route

ctx.Request.Route contains the information generated by GOX after the request is resolved.

It allows to consult the pattern used during the routing, the dynamic parameters extracted from the URL and other data related to the route that finally met the request.

See the full documentation at Route.


Headers

ctx.Request.Headers contains all HTTP headers sent by the client.

It allows to consult individual or multiple values using a common collection interface used by GOX.

See the full documentation at Headers.


Cookies

ctx.Request.Cookies contains cookies sent by the client along with the request.

It allows you to consult one or more cookies using the same collection interface used by the rest of the collections of Request.

See the full documentation at Cookies.


Query

ctx.Request.Query provides access to the query parameters included in the URL.

It is useful for reading filters, searches, pages and any other data sent through the query string.

See the full documentation at Query.


Form

ctx.Request.Form contains the fields sent by HTTP forms.

Allows access to encoded forms such as application/x-www-form-urlencoded and multipart/form-data.

See the full documentation at Form.


Body

ctx.Request.Body provides access to the body of the request.

The same object is also available directly by ctx.Body, which is usually the recommended way to access this functionality from pages and actions.

See the full documentation at Body.


Best practices

  • Use Method() to consult the HTTP method received.
  • Use IP() when you need to identify the client who made the request.
  • Use URL to work with the URL in a structured way.
  • Use Headers and Cookies to consult the information sent by the client.
  • Use Query to read reference parameters.
  • Use Form to work with forms and file loads.
  • Use Route to access the routing information.
  • Use ctx.Body to work with the body of the request.

To learn more about ContextSee your documentation. To learn more about Response, check your documentation.


See also

Next step

Continue with the documentation for URL to learn how to access the schema, host, port, route and other components of the URL.

URL