In practicality, cookies are used to remember user name, session state, preferences and any other information that a web application wishes to keep on a client device.
So cookies are quite important for any web application or service. In this example, we'll set a single cookie (name of the user), and then we will retrieve it later. Very simple, but it's the foundation of what you'd need to do in pretty much any application.
First, in a separate directory, create an application "yum" (as in cookies are delicious):
gg -k yum
Copied!

Next, create this source code file "biscuit.golf" (for everyone outside the US who feels it should have been "biscuit" instead of "cookie"):
begin-handler /biscuit get-param action if-true action equal "enter-cookie" // Display a form to get cookie value @<h2>Enter your name</h2> @<form action="<<p-path "/biscuit">>" method="POST"> @ <input type="hidden" name="action" value="save-cookie"> @ <label for="cookie-value">Your name:</label><br/> @ <input type="text" name="cookie-value" value=""><br/> @ <br/> @ <input type="submit" value="Submit"> @</form> else-if action equal "save-cookie" // Submittal of form: save the cookie through response to the browser get-param cookie_value get-time to cookie_expiration year 1 timezone "GMT" set-cookie "customer-name" = cookie_value expires cookie_expiration path "/" @Cookie sent to browser! @<hr/> else-if action equal "query-cookie" // Web request that delivers cookie value back here (to server); display it. get-cookie name="customer-name" @Customer name is <<p-web name>> @<hr/> else-if @Unrecognized action<hr/> end-if end-handlerCopied!

The code is pretty easy: if "action" URL parameter is "enter-cookie", you can enter your name. Then, when you submit this web form (passing back "action" parameter with value "save-cookie"), the cookie named "customer-name" is saved with the value you entered, and the cookie expiration is set 1 year into the future. Then you'll query the cookie value in another request ("query-cookie" as "action" parameter), and you'll get your name back because it was saved on the client.
Okay, so compile the application (with all request handlers public):
gg -q --publicCopied!

Now, start the Golf server to serve up your yummy application:
mgrg -p 3000 yumCopied!

"-p 3000" means it will run on socket port 3000, and the reason for that will become apparent momentarily.
We'll use HAProxy as a web server in this instance to demostrate that you can use Golf with pretty much any web server or load balancer. To set it up, here is the simple config file (typically in "/etc/haproxy/haproxy.cfg"). Note that "frontend", "fcgi-app" and "backend" sections are relevant to us here; the rest can be as it is by default in whatever configuration file you have:
frontend front_server mode http bind *:90 use_backend backend_servers if { path_reg -i ^.*\/yum\/.*$ } option forwardfor fcgi-app golf-fcgi log-stderr global docroot /var/lib/gg/yum/app path-info ^.+(/yum)(/.+)$ backend backend_servers mode http filter fcgi-app golf-fcgi use-fcgi-app golf-fcgi server s1 127.0.0.1:3000 proto fcgiCopied!

So, the HAProxy server will respond on port 90 from the web. We specify that it will redirect any URL starting with "/yum/" to your Golf application. Obviously, if you change your application name from "yum" to something else, change "yum" here too. Then we specify we'd like to use FastCGI protocol, which Golf uses because it's very fast and capable. And finally, we tell HAProxy we'd like to communicate with our server on port 3000. So that's why we used "-p 3000" above when starting the server!
Restart HAProxy for this to take effect:
sudo systemctl restart haproxyCopied!

Now you can test your application server. Open a browser, and point it to your server where all the above code took place. If you're testing this on your own local machine, then just use "127.0.0.1" - and that's what we'll do here:
http://127.0.0.1:90/yum/biscuit/action=enter-cookieCopied!

You'd get something like this:
Enter the name, and click Submit, and you'll get the message that the cookie is saved:
Now, enter this URL to query the cookie you set:
http://127.0.0.1:90/yum/biscuit/action=query-cookieCopied!

And you'll see:
So now you've learned how to use cookies in Golf, and how to use HAProxy too. Of course, you could have used Apache, Nginx or some other web server as well.