Retrieving Input

    The Request type is most useful for retrieving input from incoming HTTP requests.

    Retrieving Querystring Values

    The Query method can be used to read input from the querystring. Since Go is a typed language, there are several methods available to read query parameters into various types.

    req.Query("search")  // "some value"
    req.QueryInt("page") // 123

    Accessing Cookies

    Cookie values can be read using the request’s Cookie method.

    sessionID := req.Cookie("session_id")

    Using the Context API

    Go’s context API is now widely used within web applications. Hemlock uses the context API behind the scenes and also allows access to the context via the Context method.

    ctx := req.Context()

    Similar to the http.Request type, Hemlock’s Request also has a WithContext method to return a shallow copy of the request with an updated context.

    ctx := context.WithValue(req.Context(), "foo", "bar")
    newReq := req.WithContext(ctx)