SlideShare a Scribd company logo
Automatic testing of (RESTful)
API documentation
Nordic APIs Platform Summit, October 2016
By Rouven Weßling ( )
Ecosystem Developer / Developer Evangelist, Contentful
@RouvenWessling
photo credit: byStockholm, Approaching Blue Hour Tobias Lindman (CC-BY)
A content management developer platform with an API at its core.
Nordic APIs - Automatic Testing of (RESTful) API Documentation
What do you do?
Powered by
Documentation will be wrong
Users hate that
It's all in the spec
api blueprint
A powerful high-level API description language for web APIs.
## Questions Collection [/questions]
### Create a New Question [POST]
You may create your own question using this action. It takes a JSON
object containing a question and a collection of answers in the
form of choices.
+ Request (application/json)
{
"question": "Favourite programming language?",
"choices": [
"Swift",
"Python",
"Objective-C",
"Ruby"
]
}
+ Response 201 (application/json)
+ Headers
Location: /questions/2
+ Body
{
"question": "Favourite programming language?",
"published_at": "2015-08-05T08:40:51.620Z",
"choices": [
{
"choice": "Swift",
Let's get testing
DREDD
No more outdated API documentation.
Testing read-only
node_modules/.bin/dredd cma.apib https://api.contentful.com 
-m GET
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Hooks
beforeAllcalled at the beginning of the whole test run
beforeEachcalled before each HTTP transaction
beforecalled before some specific HTTP transaction
beforeEachValidationcalled before each HTTP transaction is validated
beforeValidationcalled before some specific HTTP transaction is validated
aftercalled a er some specific HTTP transaction regardless its result
afterEachcalled a er each HTTP transaction
afterAllcalled a er whole test run
Hooks
node_modules/.bin/dredd cma.apib https://api.contentful.com 
--hookfiles=./test-hooks.js 
-m GET
Skipping Tests
var hooks = require('hooks');
hooks.before(
"Webhook calls > Webhook call details > Get the webhook call details",
function (transaction) {
transaction.skip = true;
});
Mutating data
var hooks = require('hooks');
hooks.before(
"Entries > Delete an Entry",
function (transaction) {
client.createEntry(entry, "1234")
});
Rate limiting
var hooks = require('hooks');
const DELAY = 1000/6.0;
hooks.afterEach(function(transaction, done) {
setTimeout(done, DELAY);
});
Changing request data
var hooks = require('hooks');
hooks.beforeEach(function (transaction, done) {
transaction.fullPath = transaction.fullPath.replace('fp91oelsziea', 'gbkxklvmolc1');
done();
});
Chai assertions
var hooks = require('hooks');
var assert = require('chai').assert;
hooks.afterEach(function(transaction, done) {
if (!transaction.skip) {
assert.match(transaction.real.headers['x-contentful-request-id'], /^content-api:[a-zA-Z0-9]{22}$/
}
done();
});
Security
Censor private data
var hooks = require('hooks');
const SECRET_HEADERS = ['Authorization'].map(header => header.toLowerCase());
hooks.afterEachValidation(function(transaction, done) {
Object.keys(transaction.request.headers).forEach(function(key) {
if (SECRET_HEADERS.indexOf(key.toLowerCase()) > -1) {
transaction.request.headers[key] = "***HIDDEN SECRET DATA***";
}
});
done();
});
CI the beast
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Conclusion
Base your documentation on an API spec
Test that spec
Make it part of your CI
Don't substitute your integration tests
Slides available on Slideshare: http://www.slideshare.net/rwessling/nordic-
apis-automatic-testing-of-restful-api-documentation
Follow me on Twitter: @RouvenWessling

More Related Content

What's hot (20)

PDF
Building a Serverless company with Node.js, React and the Serverless Framewor...
Luciano Mammino
 
PPTX
Java 8 concurrency abstractions
Nawazish Mohammad Khan
 
PDF
Building a chatbot – step by step
CodeOps Technologies LLP
 
PPTX
Automate that
Atlassian
 
PDF
Server Side Swift
Jens Ravens
 
PDF
Distributed Eventing in OSGi
Carsten Ziegeler
 
PDF
Gatling @ Scala.Io 2013
slandelle
 
PDF
WordPress RESTful API & Amazon API Gateway (English version)
崇之 清水
 
PDF
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
devopsdaysaustin
 
PDF
Maarten Balliauw "Indexing and searching NuGet.org with Azure Functions and S...
Fwdays
 
PDF
Karate - powerful and simple framework for REST API automation testing
Roman Liubun
 
PDF
Building domain-specific testing tools : lessons learned from the Apache Slin...
Robert Munteanu
 
PPTX
Azure Durable Functions
Karthikeyan VK
 
PDF
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 
PPTX
Indexing and searching NuGet.org with Azure Functions and Search - .NET fwday...
Maarten Balliauw
 
PDF
AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜
崇之 清水
 
PDF
The Works 2018 - Software Track - Development 101: Build Using API and Overvi...
David Dourgarian
 
PPTX
State in stateless serverless functions
Alex Pshul
 
PDF
Server Side Swift - AppBuilders 2017
Jens Ravens
 
PDF
Serverless Angular, Material, Firebase and Google Cloud applications
Loiane Groner
 
Building a Serverless company with Node.js, React and the Serverless Framewor...
Luciano Mammino
 
Java 8 concurrency abstractions
Nawazish Mohammad Khan
 
Building a chatbot – step by step
CodeOps Technologies LLP
 
Automate that
Atlassian
 
Server Side Swift
Jens Ravens
 
Distributed Eventing in OSGi
Carsten Ziegeler
 
Gatling @ Scala.Io 2013
slandelle
 
WordPress RESTful API & Amazon API Gateway (English version)
崇之 清水
 
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
devopsdaysaustin
 
Maarten Balliauw "Indexing and searching NuGet.org with Azure Functions and S...
Fwdays
 
Karate - powerful and simple framework for REST API automation testing
Roman Liubun
 
Building domain-specific testing tools : lessons learned from the Apache Slin...
Robert Munteanu
 
Azure Durable Functions
Karthikeyan VK
 
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 
Indexing and searching NuGet.org with Azure Functions and Search - .NET fwday...
Maarten Balliauw
 
AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜
崇之 清水
 
The Works 2018 - Software Track - Development 101: Build Using API and Overvi...
David Dourgarian
 
State in stateless serverless functions
Alex Pshul
 
Server Side Swift - AppBuilders 2017
Jens Ravens
 
Serverless Angular, Material, Firebase and Google Cloud applications
Loiane Groner
 

Viewers also liked (20)

PDF
php[world] 2016 - API Mashup - Combining APIs for Fun and Profit
Rouven Weßling
 
PDF
Adapting our API for multiple platforms
Rouven Weßling
 
PDF
HCLT Whitepaper: Multi- Tenancy on Private Cloud
HCL Technologies
 
PPTX
In sight telepsychiatry competitor profiles tracey fu
traceyxfu
 
PDF
Best Practices for API Adoption
AnyPresence
 
PDF
A RESTful API for Controlling Dynamic Streaming Topologies
Masiar Babazadeh
 
PPTX
Charity Business Automation
Mohamed Shaaban
 
PDF
SITB15 - Qu'est qu'une Data Driven Company à l'heure de la digitalisation ?
cyrilpicat
 
PPTX
USF Mid East and Turkey Pitch
Contractor
 
PDF
Plaquette Commerciale Phone Contact
phonecontact
 
PPTX
Structure 2014 - The future of cloud computing survey results
Gigaom
 
PDF
Canada Digital Future 2014
Counselorauto
 
PPT
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
Sales Hacker
 
PDF
Education and Training for The Future Workforce
WISE
 
PDF
Dynamic clouds and networks without infrastructure
University of Hertfordshire
 
PDF
APIs and Innovation
Liad Bokovsky
 
PDF
China air conditioner market report
Beijing Zeefer Consulting Ltd.
 
PDF
Ripening of a RESTful API
Dr. Alexander Schwartz
 
PPTX
Integrated Customer Service Maximization Experience Vision Demonstrator
Microsoft
 
php[world] 2016 - API Mashup - Combining APIs for Fun and Profit
Rouven Weßling
 
Adapting our API for multiple platforms
Rouven Weßling
 
HCLT Whitepaper: Multi- Tenancy on Private Cloud
HCL Technologies
 
In sight telepsychiatry competitor profiles tracey fu
traceyxfu
 
Best Practices for API Adoption
AnyPresence
 
A RESTful API for Controlling Dynamic Streaming Topologies
Masiar Babazadeh
 
Charity Business Automation
Mohamed Shaaban
 
SITB15 - Qu'est qu'une Data Driven Company à l'heure de la digitalisation ?
cyrilpicat
 
USF Mid East and Turkey Pitch
Contractor
 
Plaquette Commerciale Phone Contact
phonecontact
 
Structure 2014 - The future of cloud computing survey results
Gigaom
 
Canada Digital Future 2014
Counselorauto
 
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
Sales Hacker
 
Education and Training for The Future Workforce
WISE
 
Dynamic clouds and networks without infrastructure
University of Hertfordshire
 
APIs and Innovation
Liad Bokovsky
 
China air conditioner market report
Beijing Zeefer Consulting Ltd.
 
Ripening of a RESTful API
Dr. Alexander Schwartz
 
Integrated Customer Service Maximization Experience Vision Demonstrator
Microsoft
 
Ad

Similar to Nordic APIs - Automatic Testing of (RESTful) API Documentation (20)

PDF
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
PDF
Play 23x Documentation For Scala Developers 23x Unknown
maistojayde
 
PPTX
Full Stack Development with Node.js and NoSQL
All Things Open
 
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves
 
PPTX
Crafting Evolvable Api Responses
darrelmiller71
 
PDF
Building Better Web APIs with Rails
All Things Open
 
PPTX
Externalizing Authorization in Micro Services world
Sitaraman Lakshminarayanan
 
PDF
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
Amazon Web Services Japan
 
PDF
Velocity EU 2014 — Offline-first web apps
andrewsmatt
 
PDF
Rethinking Syncing at AltConf 2019
Joe Keeley
 
PPTX
Sharding and Load Balancing in Scala - Twitter's Finagle
Geoff Ballinger
 
PPTX
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
BizTalk360
 
PPTX
Saving Time And Effort With QuickBase Api - Sergio Haro
QuickBase, Inc.
 
PPTX
Prairie DevCon 2015 - Crafting Evolvable API Responses
darrelmiller71
 
PDF
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Shaun Murakami
 
PDF
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
PPTX
Introduction to the SharePoint Client Object Model and REST API
Rob Windsor
 
PPTX
Intro to Node
Aaron Stannard
 
PDF
OneRing @ OSCamp 2010
Qiangning Hong
 
KEY
CouchDB on Android
Sven Haiges
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
Play 23x Documentation For Scala Developers 23x Unknown
maistojayde
 
Full Stack Development with Node.js and NoSQL
All Things Open
 
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves
 
Crafting Evolvable Api Responses
darrelmiller71
 
Building Better Web APIs with Rails
All Things Open
 
Externalizing Authorization in Micro Services world
Sitaraman Lakshminarayanan
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
Amazon Web Services Japan
 
Velocity EU 2014 — Offline-first web apps
andrewsmatt
 
Rethinking Syncing at AltConf 2019
Joe Keeley
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Geoff Ballinger
 
Use Windows Azure Service Bus, BizTalk Services, Mobile Services, and BizTalk...
BizTalk360
 
Saving Time And Effort With QuickBase Api - Sergio Haro
QuickBase, Inc.
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
darrelmiller71
 
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Shaun Murakami
 
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
Introduction to the SharePoint Client Object Model and REST API
Rob Windsor
 
Intro to Node
Aaron Stannard
 
OneRing @ OSCamp 2010
Qiangning Hong
 
CouchDB on Android
Sven Haiges
 
Ad

More from Rouven Weßling (6)

PDF
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
Rouven Weßling
 
PDF
API World 2016 - API Mashup - Combining for Fun and Profit
Rouven Weßling
 
PDF
vienna.html - Turn your Blog into Facebook Instant Articles + Contentful Intro
Rouven Weßling
 
PDF
Static Analysis of PHP Code – IPC Berlin 2016
Rouven Weßling
 
PDF
What is the Joomla Framework and why do we need it?
Rouven Weßling
 
KEY
Joomla Day DK 2012
Rouven Weßling
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
Rouven Weßling
 
API World 2016 - API Mashup - Combining for Fun and Profit
Rouven Weßling
 
vienna.html - Turn your Blog into Facebook Instant Articles + Contentful Intro
Rouven Weßling
 
Static Analysis of PHP Code – IPC Berlin 2016
Rouven Weßling
 
What is the Joomla Framework and why do we need it?
Rouven Weßling
 
Joomla Day DK 2012
Rouven Weßling
 

Recently uploaded (20)

PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
PPTX
arctitecture application system design os dsa
za241967
 
PDF
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
PPTX
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
PPTX
declaration of Variables and constants.pptx
meemee7378
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
PDF
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
PDF
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
PPTX
Agentforce – TDX 2025 Hackathon Achievement
GetOnCRM Solutions
 
PDF
Automated Test Case Repair Using Language Models
Lionel Briand
 
PDF
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
 
PDF
Alur Perkembangan Software dan Jaringan Komputer
ssuser754303
 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
PDF
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
 
PPTX
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
arctitecture application system design os dsa
za241967
 
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
declaration of Variables and constants.pptx
meemee7378
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
Agentforce – TDX 2025 Hackathon Achievement
GetOnCRM Solutions
 
Automated Test Case Repair Using Language Models
Lionel Briand
 
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
 
Alur Perkembangan Software dan Jaringan Komputer
ssuser754303
 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
 
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
 
Rewards and Recognition (2).pdf
ethan Talor
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 

Nordic APIs - Automatic Testing of (RESTful) API Documentation

  • 1. Automatic testing of (RESTful) API documentation Nordic APIs Platform Summit, October 2016 By Rouven Weßling ( ) Ecosystem Developer / Developer Evangelist, Contentful @RouvenWessling photo credit: byStockholm, Approaching Blue Hour Tobias Lindman (CC-BY)
  • 2. A content management developer platform with an API at its core.
  • 8. It's all in the spec api blueprint A powerful high-level API description language for web APIs.
  • 9. ## Questions Collection [/questions] ### Create a New Question [POST] You may create your own question using this action. It takes a JSON object containing a question and a collection of answers in the form of choices. + Request (application/json) { "question": "Favourite programming language?", "choices": [ "Swift", "Python", "Objective-C", "Ruby" ] } + Response 201 (application/json) + Headers Location: /questions/2 + Body { "question": "Favourite programming language?", "published_at": "2015-08-05T08:40:51.620Z", "choices": [ { "choice": "Swift",
  • 10. Let's get testing DREDD No more outdated API documentation.
  • 11. Testing read-only node_modules/.bin/dredd cma.apib https://api.contentful.com -m GET
  • 14. Hooks beforeAllcalled at the beginning of the whole test run beforeEachcalled before each HTTP transaction beforecalled before some specific HTTP transaction beforeEachValidationcalled before each HTTP transaction is validated beforeValidationcalled before some specific HTTP transaction is validated aftercalled a er some specific HTTP transaction regardless its result afterEachcalled a er each HTTP transaction afterAllcalled a er whole test run
  • 16. Skipping Tests var hooks = require('hooks'); hooks.before( "Webhook calls > Webhook call details > Get the webhook call details", function (transaction) { transaction.skip = true; });
  • 17. Mutating data var hooks = require('hooks'); hooks.before( "Entries > Delete an Entry", function (transaction) { client.createEntry(entry, "1234") });
  • 18. Rate limiting var hooks = require('hooks'); const DELAY = 1000/6.0; hooks.afterEach(function(transaction, done) { setTimeout(done, DELAY); });
  • 19. Changing request data var hooks = require('hooks'); hooks.beforeEach(function (transaction, done) { transaction.fullPath = transaction.fullPath.replace('fp91oelsziea', 'gbkxklvmolc1'); done(); });
  • 20. Chai assertions var hooks = require('hooks'); var assert = require('chai').assert; hooks.afterEach(function(transaction, done) { if (!transaction.skip) { assert.match(transaction.real.headers['x-contentful-request-id'], /^content-api:[a-zA-Z0-9]{22}$/ } done(); });
  • 22. Censor private data var hooks = require('hooks'); const SECRET_HEADERS = ['Authorization'].map(header => header.toLowerCase()); hooks.afterEachValidation(function(transaction, done) { Object.keys(transaction.request.headers).forEach(function(key) { if (SECRET_HEADERS.indexOf(key.toLowerCase()) > -1) { transaction.request.headers[key] = "***HIDDEN SECRET DATA***"; } }); done(); });
  • 25. Conclusion Base your documentation on an API spec Test that spec Make it part of your CI Don't substitute your integration tests
  • 26. Slides available on Slideshare: http://www.slideshare.net/rwessling/nordic- apis-automatic-testing-of-restful-api-documentation Follow me on Twitter: @RouvenWessling