Back to course

Request and Response: The Basics

Go (Golang) for Cloud-Native Microservices

Handling Requests and Sending Responses

  • *http.Request: Contains all incoming data (Method, URL, Headers, Body).
  • http.ResponseWriter: An interface used to build the HTTP response.

Setting Headers and Status Codes:

go w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK)

You must set headers BEFORE writing the body or calling WriteHeader.