Exemple of route responding to GET requests.
class GetHandler
super Handler
redef fun get(req, res) do res.send "GETrequest received"
end
# GET handler.
#
# Exemple of route responding to GET requests.
# ~~~
# class GetHandler
# super Handler
#
# redef fun get(req, res) do res.send "GETrequest received"
# end
# ~~~
fun get(req: HttpRequest, res: HttpResponse) do end
lib/popcorn/pop_handlers.nit:125,2--135,52
redef fun get(req, res) do res.redirect build_auth_redirect
lib/popcorn/pop_auth.nit:135,2--60
redef fun get(req, res) do
# Get OAuth code
var code = req.string_arg("code")
if code == null then
res.error 401
return
end
# Exchange it for an access token
var access_token = request_access_token(code)
if access_token == null then
res.error 401
return
end
# Load github user
var gh_api = new GithubAPI(access_token)
var user = gh_api.get_auth_user
if user == null then
res.error 401
return
end
# Set session and redirect to user page
var session = req.session
if session == null then
res.error 500
return
end
session.user = user
res.redirect redirect_uri or else "/"
end
lib/popcorn/pop_auth.nit:185,2--215,4
redef fun get(req, res) do
res.json(json_counter)
end
lib/popcorn/examples/angular/example_angular.nit:35,2--37,4
redef fun get(req, res) do res.html "<h1>Hello World!</h1>"
lib/popcorn/examples/hello_world/example_hello.nit:24,2--60
redef fun get(req, res) do res.send "Hello World!"
lib/popcorn/examples/middlewares/example_advanced_logger.nit:49,2--51
redef fun get(req, res) do res.send "Hello World!"
lib/popcorn/examples/middlewares/example_simple_error_handler.nit:32,2--51
redef fun get(req, res) do res.send "Hello World!"
lib/popcorn/examples/middlewares/example_simple_logger.nit:30,2--51
redef fun get(req, res) do
var users = db.collection("users").find_all(new JsonObject)
var tpl = new Template
tpl.add """
<h1>Users</h1>
<h2>Add a new user</h2>
<form action="/" method="POST">
<input type="text" name="login" />
<input type="password" name="password" />
<input type="submit" value="save" />
</form>
<h2>All users</h2>
<table>"""
for user in users do
tpl.add """<tr>
<td>{{{user["login"] or else "null"}}}</td>
<td>{{{user["password"] or else "null"}}}</td>
</tr>"""
end
tpl.add "</table>"
res.html(tpl)
end
lib/popcorn/examples/mongodb/example_mongodb.nit:28,2--52,4
redef fun get(req, res) do res.send "User Home"
lib/popcorn/examples/routing/example_router.nit:36,2--48
redef fun get(req, res) do res.send "User Profile"
lib/popcorn/examples/routing/example_router.nit:42,2--51
redef fun get(req, res) do
# Values to add in the template
var values = new HashMap[String, String]
values["USER"] = "Morriar"
values["MYSITE"] = "My super website"
# Render it with a shortcut
res.template_string("""
<h1>Hello %USER%!</h1>
<p>Welcome to %MYSITE%.</p>
""", values)
end
lib/popcorn/examples/templates/example_templates.nit:45,2--56,4
redef fun get(req, res) do
# Values to add in the template
var values = new HashMap[String, String]
values["USER"] = "Morriar"
values["MYSITE"] = "My super website"
# Render it from an external file
res.template_file(tpl_file, values)
end
lib/popcorn/examples/templates/example_templates.nit:65,2--73,4
redef fun get(req, res) do
# Values to add in the template
var json = new JsonObject
json["user"] = "Morriar"
json["mysite"] = "My super website"
res.pug("""
h1 Hello #{user}
p Welcome to #{mysite}
""", json)
end
lib/popcorn/examples/templates/example_templates.nit:79,2--89,4
redef fun get(req, res) do
var user = check_session_user(req, res)
if user == null then return
res.json user
end
lib/popcorn/pop_auth.nit:321,2--325,4
redef fun get(req, res) do
var pipe = new MongoPipeline
pipe.group((new MongoGroup("$request.uri")).
sum("visits", 1).
avg("response_time", "$response_time").
addToSet("uniq", "$session"))
pipe.sort((new MongoMatch).eq("visits", -1))
pipe.limit(limit(req))
res.json new JsonArray.from(config.tracker_logs.collection.aggregate(pipe))
end
lib/popcorn/pop_tracker.nit:113,2--122,4
redef fun get(req, res) do
var browsers = new Array[BrowserCount]
for browser, query in self.browser_queries do
var count = new BrowserCount(browser, browser_count(query))
if count.count > 0 then browsers.add count
end
var sum = 0
for browser in browsers do sum += browser.count
var other = config.tracker_logs.count - sum
if other > 0 then browsers.add new BrowserCount("Other", other)
default_comparator.sort(browsers)
res.json new JsonArray.from(browsers)
end
lib/popcorn/pop_tracker.nit:155,2--167,4
redef fun get(req, res) do
var limit = get_time - (3600 * 24 * 30)
var pipe = new MongoPipeline
pipe.match((new MongoMatch).gte("timestamp", limit))
pipe.group((new MongoGroup("$timestamp")).
sum("visits", 1).
avg("response_time", "$response_time"))
pipe.sort((new MongoMatch).eq("_id", -1))
res.json new JsonArray.from(config.tracker_logs.collection.aggregate(pipe))
end
lib/popcorn/pop_tracker.nit:190,2--199,4