GET handler.

Exemple of route responding to GET requests.

class GetHandler
    super Handler

    redef fun get(req, res) do res.send "GETrequest received"
end

Property definitions

popcorn $ Handler :: get
	# 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

popcorn $ GithubLogin :: get
	redef fun get(req, res) do res.redirect build_auth_redirect
lib/popcorn/pop_auth.nit:135,2--60

popcorn $ GithubOAuthCallBack :: get
	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

popcorn $ GithubLogout :: get
	redef fun get(req, res) do
		var session = req.session
		if session != null then
			session.user = null
		end
		res.redirect redirect_uri or else "/"
	end
lib/popcorn/pop_auth.nit:262,2--268,4

popcorn $ CounterAPI :: get
	redef fun get(req, res) do
		res.json(json_counter)
	end
lib/popcorn/examples/angular/example_angular.nit:35,2--37,4

popcorn $ QueryStringHandler :: get
	redef fun get(req, res) do
		var tpl = new Template
		tpl.addn "URI: {req.uri}"
		tpl.addn "Query string: {req.query_string}"
		for name, arg in req.get_args do
			tpl.addn "{name}: {arg}"
		end
        res.send tpl
	end
lib/popcorn/examples/handlers/example_query_string.nit:25,2--33,4

popcorn $ HelloHandler :: get
	redef fun get(req, res) do res.html "<h1>Hello World!</h1>"
lib/popcorn/examples/hello_world/example_hello.nit:24,2--60

popcorn $ AnotherHandler :: get
	redef fun get(req, res) do res.send "Hello World!"
lib/popcorn/examples/middlewares/example_advanced_logger.nit:49,2--51

popcorn $ SomeHandler :: get
	redef fun get(req, res) do res.send "Hello World!"
lib/popcorn/examples/middlewares/example_simple_error_handler.nit:32,2--51

popcorn $ MyOtherHandler :: get
	redef fun get(req, res) do res.send "Hello World!"
lib/popcorn/examples/middlewares/example_simple_logger.nit:30,2--51

popcorn $ UserItem :: get
	redef fun get(req, res) do
		var user = req.param("user")
		var item = req.param("item")
		if user == null or item == null then
			res.send("Nothing received", 400)
		else
			res.send "Here the item {item} of the use {user}."
		end
	end
lib/popcorn/examples/routing/example_glob_route.nit:24,2--32,4

popcorn $ UserHome :: get
	redef fun get(req, res) do
		var user = req.param("user")
		if user != null then
			res.send "Hello {user}"
		else
			res.send("Nothing received", 400)
		end
	end
lib/popcorn/examples/routing/example_param_route.nit:24,2--31,4

popcorn $ AppHome :: get
	redef fun get(req, res) do res.send "Site Home"
lib/popcorn/examples/routing/example_router.nit:24,2--48

popcorn $ UserHomepage :: get
	redef fun get(req, res) do res.send "User Home"
lib/popcorn/examples/routing/example_router.nit:36,2--48

popcorn $ UserProfile :: get
	redef fun get(req, res) do res.send "User Profile"
lib/popcorn/examples/routing/example_router.nit:42,2--51

popcorn $ MyTemplateHandler :: get
	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
		res.template(template, values)
	end
lib/popcorn/examples/templates/example_templates.nit:31,2--39,4

popcorn $ MyTemplateStringHandler :: get
	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

popcorn $ MyTemplateFileHandler :: get
	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

popcorn $ MyTemplatePugHandler :: get
	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

popcorn $ MyTemplatePugFileHandler :: get
	redef fun get(req, res) do
		# Values to add in the template
		var json = new JsonObject
		json["user"] = "Morriar"
		json["mysite"] = "My super website"

		# Render it from an external file
		res.pug_file(pug_file, json)
	end
lib/popcorn/examples/templates/example_templates.nit:98,2--106,4

popcorn $ TestHandler :: get
	redef fun get(req, res) do res.send marker
lib/popcorn/tests/test_popcorn.nit:27,2--43

popcorn $ GithubUser :: get
	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

popcorn $ PopTrackerEntries :: get
	redef fun get(req, res) do
		res.json new JsonArray.from(config.tracker_logs.find_all)
	end
lib/popcorn/pop_tracker.nit:104,2--106,4

popcorn $ PopTrackerBrowsers :: get
	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