-
Notifications
You must be signed in to change notification settings - Fork 39
Request
The request
object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on. In this documentation and by convention, the object is always referred to as request
(and the HTTP response is response
) but its actual name is determined by the parameters to the callback function in which you’re working.
For example:
app.get("/user/:id") { request, response in
response.send(text: 'user ' + request.data["id"])
}
But you could just as well have:
app.get("/user/:id") { req, res in
res.send(text: 'user ' + req.data["id"])
}
The request method that was used. Can be .POST
, .GET
, .PUT
, .PATCH
, .DELETE
The URL parameters that were specified in the request
/user/:id would provide the parameter id
, which would be accessible via request.params["id"]
Any POST or PUT type data, such as JSON or Form data
The requests cookies
The path of the request
The RAW request body. See the Data struct for more details
The Host address of the request
Any multipart files that were uploaded. These required the Multiparser()
middleware to be added into the stack.
The current request session.
Opens up access to the headers of the request. Such as Content-Type
Allows access to set a new header or overwrite an original one.