module Grip::Extensions::Context

Direct including types

Defined in:

grip/extensions/context.cr

Instance Method Summary

Instance Method Detail

def binary(content : ::String | Bytes, content_type : ::String = "application/octet-stream") : self #

Sends a response with content as binary data. Sets the Content-Type header to the specified content_type. Returns self for method chaining.


[View source]
def client_ip : Socket::IPAddress | Nil #

[View source]
def client_ip=(client_ip : Socket::IPAddress | Nil) #

[View source]
def delete_req_header(key : ::String) : self #

Deletes a request header by key. Returns self for method chaining.


[View source]
def delete_resp_header(key : ::String) : self #

Deletes a response header by key. Returns self for method chaining.


[View source]
def exception : Exception | Nil #

[View source]
def exception=(exception : Exception | Nil) #

[View source]
def exec(&) #

Executes a block with self as the context. Returns the result of the block.


[View source]
def fetch_body_params : URI::Params #

Fetches parsed URL-encoded body parameters from the request. Returns an empty hash if no parameters are available.


[View source]
def fetch_file_params : Hash(::String, Parsers::FileUpload) #

Fetches parsed multipart file data from the request. Returns an empty hash if no parameters are available.


[View source]
def fetch_json_params : Hash(::String, Parsers::ParameterBox::AllParamTypes) #

Fetches parsed JSON parameters from the request. Returns an empty hash if no parameters are available.


[View source]
def fetch_path_params : Hash(::String, ::String) #

Fetches parsed URL path parameters from the request. Returns an empty hash if no parameters are available.


[View source]
def fetch_query_params : URI::Params #

Fetches parsed GET query parameters from the request. Returns an empty hash if no parameters are available.


[View source]
def get_req_cookie(key : ::String) : HTTP::Cookie | Nil #

Gets a cookie from the request by key, returns nil if not found.


[View source]
def get_req_header(key : ::String) : ::String #

Gets a request header by key, raises KeyError if not found. Use #get_req_header? for a nil-safe alternative.


[View source]
def get_req_header?(key : ::String) : ::String | Nil #

Gets a request header by key, returns nil if not found.


[View source]
def get_resp_header(key : ::String) : ::String #

Gets a response header by key, raises KeyError if not found.


[View source]
def halt : self #

Halts endpoint execution by closing the response. Returns self for method chaining.


[View source]
def html(content : ::String, content_type : ::String = "text/html; charset=UTF-8") : self #

Sends a response with content formatted as HTML. Sets the Content-Type header to the specified content_type. Returns self for method chaining.


[View source]
def json(content, content_type : ::String = "application/json") : self #

Sends a response with content formatted as JSON. Sets the Content-Type header to the specified content_type. Returns self for method chaining.


[View source]
def merge_resp_headers(headers : Hash(::String, ::String)) : self #

Merges the given headers into the response headers. Returns self for method chaining.


[View source]
def parameters : Grip::Parsers::ParameterBox | Nil #

[View source]
def parameters=(parameters : Grip::Parsers::ParameterBox | Nil) #

[View source]
def put_req_header(key : ::String, value : ::String) : self #

Assigns a request header with the given key and value. Returns self for method chaining.


[View source]
def put_resp_cookie(key : ::String, value : ::String) : self #

Sets a response cookie with the given key and value as a string. Returns self for method chaining.


[View source]
def put_resp_cookie(cookie : HTTP::Cookie) : self #

Sets a response cookie with the given cookie object. Returns self for method chaining.


[View source]
def put_resp_header(key : ::String, value : ::String) : self #

Assigns a response header with the given key and value. Returns self for method chaining.


[View source]
def put_status(status_code : HTTP::Status = HTTP::Status::OK) : self #

Assigns the response status code. Returns self for method chaining.


[View source]
def put_status(status_code : Int32 = 200) : self #

Assigns the response status code. Returns self for method chaining.


[View source]
def redirect(url : ::String = "/", status_code : HTTP::Status = HTTP::Status::FOUND) : self #

Redirects the response to the specified URL with a given status code. Returns self for method chaining.


[View source]
def redirect(url : ::String = "/", status_code : Int32 = 302) : self #

[View source]
def send_file(path : ::String, mime_type : ::String | Nil = nil, gzip_enabled : Bool = false) : self #

Sends a file as the response. path must point to an existing file. mime_type can be specified, otherwise inferred from the file extension. gzip_enabled enables gzip compression if supported. Returns self for method chaining.


[View source]
def send_resp(content : ::String) : self #

Sends a response with the given content and a status code of OK. Returns self for method chaining.


[View source]
def text(content : ::String, content_type : ::String = "text/plain; charset=UTF-8") : self #

Sends a response with content formatted as plain text. Sets the Content-Type header to the specified content_type. Returns self for method chaining.


[View source]