Today's tip: From Hello, World to hired.

Courses / Intermediate

Build APIs with Go

HTTP handlers, JSON, middleware and tests with nothing but the standard library. Then Postgres and deployment.

8 lessons10 hours97k learnersCertificate with Pro

Start the free first lesson

Code you'll write

Your first HTTP servergo
package main

import (
	"fmt"
	"net/http"
)

func main() {
	http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %s!\n", r.URL.Query().Get("name"))
	})
	http.ListenAndServe(":8080", nil)
}
JSON in and outgo
type Todo struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
	Done  bool   `json:"done"`
}

func list(w http.ResponseWriter, r *http.Request) {
	todos := []Todo{{1, "Learn Go", true}, {2, "Ship it", false}}
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(todos)
}