Top Level Namespace

Defined in:

Method Summary

Method Detail

def delete(path, &handler : Hatty::Handler) #

[View source]
def delete(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response #

Sends a DELETE requests for resource.

NOTE Only available by importing hatty/testing.

delete "/" do |request, response|
  response.send_status 401
end
response = delete "/"
response.status_code # -> 401

[View source]
def get(path : String, &handler : Hatty::Handler) #

Listen for GET requests on path.

Example: Imaginary "get user" endpoint.

get "/api/users/:id" do |request, response|
  user = MyApi.get_user_by_id(request.params["id"])
  response.send_json({ data: user })
end

[View source]
def get(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response #

Sends a GET requests for resource.

NOTE Only available by importing hatty/testing.

get "/" do |request, response|
  response.send_status 401
end
response = get "/"
response.status_code # -> 401

[View source]
def patch(path, &handler : Hatty::Handler) #

[View source]
def patch(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response #

Sends a PATCH requests for resource.

NOTE Only available by importing hatty/testing.

patch "/" do |request, response|
  response.send_status 401
end
response = patch "/"
response.status_code # -> 401

[View source]
def post(path : String, &handler : Hatty::Handler) #

Listen for POST requests at path.

Example: Imaginary "create user" endpoint.

post "/api/users" do |request, response|
  user = MyApi.create_user(request.body.user)
  response.send_json({ data: user })
end

[View source]
def post(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response #

Sends a POST requests for resource.

NOTE Only available by importing hatty/testing.

post "/" do |request, response|
  response.send_status 401
end
response = post "/"
response.status_code # -> 401

[View source]
def put(path, &handler : Hatty::Handler) #

[View source]
def put(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response #

Sends a PUT requests for resource.

NOTE Only available by importing hatty/testing.

put "/" do |request, response|
  response.send_status 401
end
response = put "/"
response.status_code # -> 401

[View source]
def status(code, &handler : Hatty::Handler) #

[View source]
def status(&handler : Hatty::GlobalStatusHandler) #

This creates a "global status handler". This is like a status code handler, but receives all unhandled status codes.

NOTE This can only be used once.

get "/unhandled" do |request, response|
  response.send_status 410
end

status do |code, request, response|
  response.send_text "Code: #{code}"
end

# GET /unhandled
# > "Code: 410"

[View source]