all
is a special request handler, which is not derived from any
HTTP method. This method is used to respond at a path for all request methods.
In the following example, the handler will be executed for requests to "/user" whether you are using GET, POST, PUT, DELETE, or any other HTTP request method.
class AllHandler
super Handler
redef fun all(req, res) do res.send "Every request to the homepage"
end
Using the all
method you can also implement other HTTP request methods.
class MergeHandler
super Handler
redef fun all(req, res) do
if req.method == "MERGE" then
# handle that method
else super # keep handle GET, POST, PUT and DELETE methods
end
end
# Handler to all kind of HTTP request methods.
#
# `all` is a special request handler, which is not derived from any
# HTTP method. This method is used to respond at a path for all request methods.
#
# In the following example, the handler will be executed for requests to "/user"
# whether you are using GET, POST, PUT, DELETE, or any other HTTP request method.
#
# ~~~
# class AllHandler
# super Handler
#
# redef fun all(req, res) do res.send "Every request to the homepage"
# end
# ~~~
#
# Using the `all` method you can also implement other HTTP request methods.
#
# ~~~
# class MergeHandler
# super Handler
#
# redef fun all(req, res) do
# if req.method == "MERGE" then
# # handle that method
# else super # keep handle GET, POST, PUT and DELETE methods
# end
# end
# ~~~
fun all(req: HttpRequest, res: HttpResponse) do
if req.method == "GET" then
get(req, res)
else if req.method == "POST" then
post(req, res)
else if req.method == "PUT" then
put(req, res)
else if req.method == "DELETE" then
delete(req, res)
else
res.status_code = 405
end
end
lib/popcorn/pop_handlers.nit:82,2--123,4
redef fun all(req, res) do
if res.status_code != 200 then
res.send(new HtmlErrorTemplate(res.status_code, "An error occurred!"))
end
end
lib/popcorn/examples/middlewares/example_html_error_handler.nit:44,2--48,4
redef fun all(req, res) do
if res.status_code != 200 then
res.send("An error occurred!", res.status_code)
end
end
lib/popcorn/examples/middlewares/example_simple_error_handler.nit:22,2--26,4
redef fun all(req, res) do print "Request Logged"
lib/popcorn/examples/middlewares/example_simple_logger.nit:24,2--50
redef fun all(req, res) do print "User logged"
lib/popcorn/examples/routing/example_router.nit:30,2--47