HTTP testing

In Chapter 11, Writing Networked Services, we saw that Go offers first-class APIs to build client and server programs using HTTP. The net/http/httptest sub-package, part of the Go standard library, facilitates the testing automation of both HTTP server and client code, as discussed in this section.

To explore this space, we will implement a simple API service that exposes the vector operations (covered in earlier sections) as HTTP endpoints. For instance, the following source snippet partially shows the methods that make up the server (for a complete listing, see https://github.com/vladimirvivien/learning-go/ch12/service/serv.go):

package main import ( "encoding/json" "fmt" "net/http" "github.com/vladimirvivien/learning-go/ch12/vector" ...

Get Go: Design Patterns for Real-World Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.