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
Code you'll write
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)
}
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)
}