Declarative HTTP API Testing with gabbi

While HTTP APIs are ubiquitous these days, testing and documenting such APIs
remains somewhat awkward: Tests usually consist of procedural code that is
specific to the respective language or even framework - which is neither very
expressive nor easy to maintain.

gabbi promises relief by providing a
language-agnostic, nicely readable and lightweight format for testing - and
thus describing - HTTP APIs. Originally created as part of an effort to
improve OpenStack’s APIs, it has since
grown into a useful tool for anyone working with HTTP.

gabbi tests are simply YAML files that
describe HTTP requests and responses. We’ll be using the wonderful
httpbin for illustration purposes:

method and status are optional, but it’s nice to be explicit. In fact,
gabbi itself states that the name is “derived from ‘gabby’: excessively
talkative” - i.e. gabbi prefers direct visibility and readability.

Obviously coercing httpbin into providing hypermedia responses is a bit of a
hack, so we’ll stop here. Hopefully this is sufficient to get started - in a
future post, we might expand on this with a more realistic example. We might
also delve into gabbi’s extensibility, e.g. creating a custom response handler
to query HTML responses with CSS selectors.