Request and Response objects are available to the controller as
request and response methods.
It serves both to perform requests by an HTTP::Client and to represent requests received by an HTTP::Server. A request always holds an IO as a body. When creating a request with a String or Bytes its body will be a IO::Memory wrapping these, and the
Content-Length header will be set appropriately.
The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the Crystal API Documentation https://crystal-lang.org/api/latest/HTTP/Request.html
The hostname used for this request.
The hostname's first
The content type requested by the client.
The HTTP method used for the request.
get?, post?, patch?, put?, delete?, head?
Returns true if the HTTP method is GET/POST/PATCH/PUT/DELETE/HEAD.
Returns a hash containing the headers associated with the request.
The port number (integer) used for the request.
Returns a string containing the protocol used plus "://", for example "http://".
The query string part of the URL, i.e., everything after "?".
The IP address of the client via cookie headers.
The entire URL used for the request.
The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values. To get a full list of the available methods, refer to the https://crystal-lang.org/api/latest/HTTP/Server/Response.html
This is the string of data being sent back to the client. This is most often HTML.
The HTTP status code for the response, like 200 for a successful request or 404 for file not found.
The URL the client is being redirected to, if any.
The content type of the response.
The character set being used for the response. Default is "utf-8".
Headers used for the response.