Api By Example
...an approach to testing across services
Before (monolith)
The Goal (service-based)
We wanted to split it up:
Smaller specialised services
Backend services: API (Django/DRF)
UI: service consumer (AngularJS)
Case in point: the UI
2 teams:
AngularJS single-page app
Django Backend
How We Wanted to Work
Both teams able to work independently
UI team should not be blocked by backend team
Both sub-systems testable separately
Backend team should not dictate the API
The ABE format
Api By Example
An API is described with example
request/response exchanges
These examples are in JSON files (ABE
format)
An ABE
file:
{
"description": "Retrieve a specific user",
"url": "/json/users/[0-9]+",
"method": "GET",
"examples": {
"OK": {
"description": "User response with id of 1",
"request": {
"url": "/json/users/1"
},
"response": {
"status": 200,
"body": {
"id": 1,
"first-name": "Joe",
"last-name": "Bloggs",
"age": 29,
"address": {
"street": "12 Springfield Road",
"county": "Surrey",
"postcode": "SM5 7AQ"
} } } } } }
The repos
3 repos:
mocks: API samples
The service provider
The service consumer
The process
It all begins with a PR to the mocks
repo:
PR to be OK’d by producer and consumer
PR is a documented discussion of the API
The end ABE files are a documented API
A merged PR -> a new API release
Mocks as a dependency
Mocks are a versioned dependency in
producer and consumer
Python-friendly: pip install / requirements.txt
Front-end friendly: bower install / bower.json
A new API release: at least 2 PRs, to producer and
consumer(s), to update version
Tooling
ABE-protractor:
Populate a mock backend with ABE samples in
protractor tests
ABE-python
Parse ABE files for usage in API tests
others...
Want to contribute?
Still much a work in progress.
Let’s have a chat if you’re interested.
Carles Barrobés
@technomilk
github.com/txels
github.com/apibyexample

ABE lightning talk

  • 1.
    Api By Example ...anapproach to testing across services
  • 2.
  • 3.
    The Goal (service-based) Wewanted to split it up: Smaller specialised services Backend services: API (Django/DRF) UI: service consumer (AngularJS)
  • 4.
    Case in point:the UI 2 teams: AngularJS single-page app Django Backend
  • 5.
    How We Wantedto Work Both teams able to work independently UI team should not be blocked by backend team Both sub-systems testable separately Backend team should not dictate the API
  • 6.
    The ABE format ApiBy Example An API is described with example request/response exchanges These examples are in JSON files (ABE format)
  • 7.
    An ABE file: { "description": "Retrievea specific user", "url": "/json/users/[0-9]+", "method": "GET", "examples": { "OK": { "description": "User response with id of 1", "request": { "url": "/json/users/1" }, "response": { "status": 200, "body": { "id": 1, "first-name": "Joe", "last-name": "Bloggs", "age": 29, "address": { "street": "12 Springfield Road", "county": "Surrey", "postcode": "SM5 7AQ" } } } } } }
  • 8.
    The repos 3 repos: mocks:API samples The service provider The service consumer
  • 9.
    The process It allbegins with a PR to the mocks repo: PR to be OK’d by producer and consumer PR is a documented discussion of the API The end ABE files are a documented API A merged PR -> a new API release
  • 10.
    Mocks as adependency Mocks are a versioned dependency in producer and consumer Python-friendly: pip install / requirements.txt Front-end friendly: bower install / bower.json A new API release: at least 2 PRs, to producer and consumer(s), to update version
  • 11.
    Tooling ABE-protractor: Populate a mockbackend with ABE samples in protractor tests ABE-python Parse ABE files for usage in API tests others...
  • 12.
    Want to contribute? Stillmuch a work in progress. Let’s have a chat if you’re interested. Carles Barrobés @technomilk github.com/txels github.com/apibyexample