Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Standard Library: `net/http | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 18 of 60

·Go

Standard Library: `net/http` – Building a Simple Web Server

25 minutes

Course progress30%

net/http Basics

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

Go’s standard library ships a fully‑featured HTTP server.

package main

import (
    "fmt"
    "log"
    "net/http"
)

  {
    fmt.Fprintln(w, )
}

 {
    http.HandleFunc(, helloHandler)
    log.Println()
    log.Fatal(http.ListenAndServe(, )
}
func
helloHandler
(w http.ResponseWriter, r *http.Request)
"Hello, Go HTTP!"
func main()
"/hello"
"Server listening on :8080"
":8080"
nil

Routing with http.ServeMux

mux := http.NewServeMux()
mux.HandleFunc("/", home)
mux.HandleFunc("/api", apiHandler)
http.ListenAndServe(":8080", mux)

Middleware pattern (logging)

func logging(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        log.Printf("%s %s", r.Method, r.URL.Path)
        next.ServeHTTP(w, r)
    })
}

http.ListenAndServe(":8080", logging(mux))

Info

For production‑grade routing, consider third‑party routers like gorilla/mux or chi.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonThe `context` Package – Cancellation & TimeoutsContinue to lesson 19JSON Marshalling & UnmarshallingBack to Go Programming Bootcamp curriculum