Top Level Namespace
Defined in:
Method Summary
- delete(path, &handler : Hatty::Handler)
-
delete(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response
Sends a
DELETE
requests for resource. -
get(path : String, &handler : Hatty::Handler)
Listen for
GET
requests on path. -
get(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response
Sends a
GET
requests for resource. - patch(path, &handler : Hatty::Handler)
-
patch(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response
Sends a
PATCH
requests for resource. -
post(path : String, &handler : Hatty::Handler)
Listen for
POST
requests at path. -
post(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response
Sends a
POST
requests for resource. - put(path, &handler : Hatty::Handler)
-
put(resource, headers : HTTP::Headers? = nil, body : String? = nil) : Hatty::Testing::Response
Sends a
PUT
requests for resource. - status(code, &handler : Hatty::Handler)
-
status(&handler : Hatty::GlobalStatusHandler)
This creates a "global status handler".
Method Detail
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
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
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
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
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
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
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
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"