Chapter 15 - Web Apps
Exercise 2: Query Parameters
We’ve set up a getParameter
function for you, which can read the value of a query parameter.
Your task is to use getParameter
in a web app. You’ll be writing a request handler function that takes a query parameter and displays it as an HTML <h1>
heading.
- Set up a handler function that can be passed to http.HandleFunc (that is, it must accept http.ResponseWriter and *http.Request parameters).
- Within the function, call
getParameter
to get the value of the “text” parameter. - Write the returned string out the the response in an <h1> HTML tag.
- Within the function, call
- Within
main
:- Set up your function to handle requests for the “/big” path.
- Then start an HTTP server on port 8080.
When you’re done, start your app and try visiting these URLs:
http://localhost:8080/big?text=Hello
http://localhost:8080/big?text=Head%20First%20Go
http://localhost:8080/big?text=Your%20Name%20Here