class Tiny::Request

Overview

A facade which sits in front of HTTP::Request, providing a few helper methods. The object is passed into the block of Tiny's serve method.

serve do |request, response|
  # Handle a GET request
  request.get do
    # Code here is run only for GET requests...
  end

  # Handle a POST request
  request.post do
    # Code here is run only for POST requests...
  end
end

Defined in:

tiny/request.cr

Constructors

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(context : HTTP::Server::Context) #

Create the request object


[View source]

Instance Method Detail

def delete(&block) #

Specify a block to handle DELETE requests

request.delete do
  # Code here is run only for DELETE requests...
end

[View source]
def get(&block) #

Specify a block to handle GET requests

request.get do
  # Code here is run only for GET requests...
end

[View source]
def handlers : Hash(Tiny::Request::Method, -> Nil) #

[View source]
def head(&block) #

Specify a block to handle HEAD requests

request.head do
  # Code here is run only for HEAD requests...
end

[View source]
def options(&block) #

Specify a block to handle OPTIONS requests

request.options do
  # Code here is run only for OPTIONS requests...
end

This is specified automatically by Tiny, in order to implement Access Control. If you override the #options handler you will need to handle this yourself.


[View source]
def params : Hash(String, Array(JSON::Type) | Bool | Float64 | Hash(String, JSON::Type) | Int64 | String | Nil) #

The request parameters for this request


[View source]
def patch(&block) #

Specify a block to handle PATCH requests

request.patch do
  # Code here is run only for PATCH requests...
end

[View source]
def post(&block) #

Specify a block to handle POST requests

request.post do
  # Code here is run only for POST requests...
end

[View source]
def put(&block) #

Specify a block to handle PUT requests

request.put do
  # Code here is run only for PUT requests...
end

[View source]

Macro Detail

macro method_missing(call) #

Cascade missing methods down to the server request


[View source]