Back to course

Introduction to net/http

Go (Golang) for Cloud-Native Microservices

The Built-in Web Server

Unlike many languages, Go includes a production-ready HTTP server in its standard library: net/http.

The Simplest Server:

go package main

import ( "fmt" "net/http" )

func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello World") })

http.ListenAndServe(":8080", nil)

}

This is the core of every Go microservice.