RESTful Go: An API Server with 90%+ Test Coverage in 260 Lines of Code
I wanted to try building a small, RESTful API for a mobile app. And, like any respectable piece of software, I wanted close to 100% test coverage.
The Premise: Signature Collection for Petitions
I built an API to collect signatures for online petitions. Each signature is composed of a name, age, and short message. The server responds to the following requests:
|GET||/signatures||List all signatures|
|POST||/signatures||Create a signature|
- Martini: A Go web framework, like Sinatra. Used for routing.
- mgo: Pronounced “mango”. A Go driver for MongoDB, used to persist the signatures.
- Ginkgo & Gomega: Essential for Go unit testing.
- gory: Used to easily create signatures for unit testing.
If you’re following along at home, you’ll need to
go get these libraries:
go get github.com/go-martini/martini go get github.com/martini-contrib/binding go get
Continue reading →