In-class Go Exercise 3
Exercise · Explain This Go API Handler (HTTP Response)
Go · Beginner+package main
import (
"fmt"
"net/http"
)
func healthCheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "API is running")
}
func main() {
http.HandleFunc("/health", healthCheck)
http.ListenAndServe(":8080", nil)
}
🎯 Instructions oral task
- Explain what this program does.
- Describe the purpose of the
healthCheckfunction. - Explain what
http.ResponseWriteris used for. - Explain what the request parameter represents.
- Describe what
StatusOKmeans. - Explain what message gets returned to the client.
- Explain what happens when someone visits
/health.
📖 Vocabulary core
- HTTP handler — function that processes web requests.
- endpoint — URL path used to access an API feature.
- response — data sent back to the client.
- status code — numeric HTTP result like 200 or 404.
- request — incoming communication from a client.
- server — application that listens for network requests.
- client — user or application making the request.
🧩 Collocations natural English
- handle an HTTP request
- return a response
- send back a status code
- listen on a port
- expose an API endpoint
- write data to the response
🗣️ Phrasal Verbs interview speech
- send back — “The server sends back a response.”
- listen on — “The application listens on port 8080.”
- set up — “The developer sets up a health check endpoint.”
- write out — “The handler writes out a message.”
💬 Useful Interview Phrases communication
- “This program creates a simple HTTP server...”
- “The endpoint is responsible for...”
- “The handler accepts a request and response writer...”
- “The server returns a 200 OK response...”
- “This endpoint can be used for monitoring or health checks.”
- “The response body contains a simple status message.”
🎤 Model Answer spoken
This Go program creates a very simple HTTP server with a health check endpoint.
The endpoint is available at /health.
The healthCheck function is an HTTP handler.
It accepts two parameters: a response writer and a request object.
The request contains information from the client request, while the response writer is used to send data back to the client.
Inside the handler, the server sends the HTTP status code 200 OK using w.WriteHeader(http.StatusOK).
This indicates that the request was successful.
After that, the program writes the message API is running to the response body using fmt.Fprintln().
In the main function, the program registers the handler for the /health endpoint and starts the web server on port 8080.
So when a user visits the endpoint, the server responds with a success message and a 200 status code.