SlideShare a Scribd company logo
Automatic testing of
(RESTful) API documentation
API Days Paris, December 2016
By Rouven Weßling ( )
Ecosystem Developer / Developer Evangelist, Contentful
@RouvenWessling
photo credit: byMusée du Louvre Dustin Gaffke (CC-BY)
A content management developer platform with an API at its core.
API Days Paris - 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
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
Hooks
beforeAll called at the beginning of the whole test run
beforeEach called before each HTTP transaction
before called before some specific HTTP transaction
beforeEachValidation called before each HTTP transaction is validated
beforeValidation called before some specific HTTP transaction is validated
after called a er some specific HTTP transaction regardless its result
afterEach called a er each HTTP transaction
afterAll called 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
API Days Paris - 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/api-days-
paris-automatic-testing-of-restful-api-documentation
Follow me on Twitter: @RouvenWessling

More Related Content

What's hot (20)

PDF
Wrangling WP_Cron - WordCamp Grand Rapids 2014
cklosowski
 
PDF
PWA 與 Service Worker
Anna Su
 
PDF
Teaching Native Qt to Talk Web
Alan Uthoff
 
PDF
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
DynamicInfraDays
 
PDF
DevOps in the era of serverless computing - Alessandro Vozza - Codemotion Ams...
Codemotion
 
PDF
Deploying a Location-Aware Ember Application
Ben Limmer
 
PPT
Grails Plugins
NexThoughts Technologies
 
PDF
Rntb20200805
t k
 
PPTX
Advance java session 8
Smita B Kumar
 
PPTX
Service workers and the role they play in modern day web apps
Mukul Jain
 
PDF
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
David Pichsenmeister
 
PPTX
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
NexThoughts Technologies
 
KEY
Background Jobs with Resque
homanj
 
PDF
Service workers
jungkees
 
KEY
GPerf Using Jesque
ctoestreich
 
PDF
Selenium sandwich-3: Being where you aren't.
Workhorse Computing
 
PDF
Advanced redux
Boris Dinkevich
 
PDF
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
Shengyou Fan
 
PPTX
Wix Automation - Core
Efrat Attas
 
PDF
Service Worker Presentation
Kyle Dorman
 
Wrangling WP_Cron - WordCamp Grand Rapids 2014
cklosowski
 
PWA 與 Service Worker
Anna Su
 
Teaching Native Qt to Talk Web
Alan Uthoff
 
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
DynamicInfraDays
 
DevOps in the era of serverless computing - Alessandro Vozza - Codemotion Ams...
Codemotion
 
Deploying a Location-Aware Ember Application
Ben Limmer
 
Grails Plugins
NexThoughts Technologies
 
Rntb20200805
t k
 
Advance java session 8
Smita B Kumar
 
Service workers and the role they play in modern day web apps
Mukul Jain
 
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
David Pichsenmeister
 
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
NexThoughts Technologies
 
Background Jobs with Resque
homanj
 
Service workers
jungkees
 
GPerf Using Jesque
ctoestreich
 
Selenium sandwich-3: Being where you aren't.
Workhorse Computing
 
Advanced redux
Boris Dinkevich
 
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
Shengyou Fan
 
Wix Automation - Core
Efrat Attas
 
Service Worker Presentation
Kyle Dorman
 

Viewers also liked (16)

PPTX
حاسب
szxc22
 
DOCX
Display Georgian College Academic Transcript
Angie Lacoursiere
 
PDF
Fuzi11 1
Ichsan Izatul
 
PDF
API World 2016 - API Mashup - Combining for Fun and Profit
Rouven Weßling
 
PPTX
The OpenStack Contribution Workflow
openstackindia
 
PPTX
Debunking Common Myths of Hadoop Backup & Test Data Management
Imanis Data
 
PDF
Pre-Con Education: Shift-Left Performance Testing for Shift-Forward Quality
CA Technologies
 
PPTX
Pronouns & possessives
Susana Barajas
 
PDF
How WebRTC ushers the next wave of e-Learning innovation
Tsahi Levent-levi
 
PPTX
Economics at university switzerland
hasansawaar
 
PPT
BDD along with Continuous Integration
Agile Testing Alliance
 
PPTX
Test Engagement - Vishal Prasad
Agile Testing Alliance
 
PDF
Test Data Management 101—Featuring a Tour of CA Test Data Manager (Formerly G...
CA Technologies
 
PDF
DCS Or PLC
guest07abe9
 
PDF
Company profile
Steve Jones
 
حاسب
szxc22
 
Display Georgian College Academic Transcript
Angie Lacoursiere
 
Fuzi11 1
Ichsan Izatul
 
API World 2016 - API Mashup - Combining for Fun and Profit
Rouven Weßling
 
The OpenStack Contribution Workflow
openstackindia
 
Debunking Common Myths of Hadoop Backup & Test Data Management
Imanis Data
 
Pre-Con Education: Shift-Left Performance Testing for Shift-Forward Quality
CA Technologies
 
Pronouns & possessives
Susana Barajas
 
How WebRTC ushers the next wave of e-Learning innovation
Tsahi Levent-levi
 
Economics at university switzerland
hasansawaar
 
BDD along with Continuous Integration
Agile Testing Alliance
 
Test Engagement - Vishal Prasad
Agile Testing Alliance
 
Test Data Management 101—Featuring a Tour of CA Test Data Manager (Formerly G...
CA Technologies
 
DCS Or PLC
guest07abe9
 
Company profile
Steve Jones
 
Ad

Similar to API Days Paris - Automatic Testing of (RESTful) API Documentation (20)

PDF
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
PDF
vienna.js - Automatic testing of (RESTful) API documentation
Rouven Weßling
 
PDF
Mastering Cypress API Testing_ A Comprehensive Guide with Examples.pdf
Steve Wortham
 
PPTX
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
PPTX
Test Design and Automation for REST API
Ivan Katunou
 
PPTX
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
COMAQA.BY
 
PDF
Next-Level API Automation Testing Techniques – Part 2
digitaljignect
 
PDF
Mobile Development integration tests
Kenneth Poon
 
PDF
TEST PPTBCHDBHBHBHVBHJEFVHJVBFHVBFHVBHFVBFHVHFVBFHVBHFVBFHVBFHVBFVBFVBHVBVBFHVB
utsavaggarwal8
 
PPTX
API testing - Japura.pptx
TharindaLiyanage1
 
PDF
Test driven development with behat and silex
Dionyshs Tsoumas
 
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
Ran Mizrahi
 
PPTX
API tESTUBGDBCJBCJFBCJBFBVJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ...
utsavaggarwal8
 
PPTX
Api testing
Keshav Kashyap
 
PDF
5 levels of api test automation
ShekharRamphal
 
PDF
Next-Level API Automation Testing Techniques – Part 1
digitaljignect
 
PPTX
Web API testing : A quick glance
Dhanalaxmi K
 
PDF
Api Testing.pdf
JitendraYadav351971
 
PDF
API testing Notes and features, difference.pdf
kunjukunjuzz904
 
Nordic APIs - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
vienna.js - Automatic testing of (RESTful) API documentation
Rouven Weßling
 
Mastering Cypress API Testing_ A Comprehensive Guide with Examples.pdf
Steve Wortham
 
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
Test Design and Automation for REST API
Ivan Katunou
 
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
COMAQA.BY
 
Next-Level API Automation Testing Techniques – Part 2
digitaljignect
 
Mobile Development integration tests
Kenneth Poon
 
TEST PPTBCHDBHBHBHVBHJEFVHJVBFHVBFHVBHFVBFHVHFVBFHVBHFVBFHVBFHVBFVBFVBHVBVBFHVB
utsavaggarwal8
 
API testing - Japura.pptx
TharindaLiyanage1
 
Test driven development with behat and silex
Dionyshs Tsoumas
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Ran Mizrahi
 
API tESTUBGDBCJBCJFBCJBFBVJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ...
utsavaggarwal8
 
Api testing
Keshav Kashyap
 
5 levels of api test automation
ShekharRamphal
 
Next-Level API Automation Testing Techniques – Part 1
digitaljignect
 
Web API testing : A quick glance
Dhanalaxmi K
 
Api Testing.pdf
JitendraYadav351971
 
API testing Notes and features, difference.pdf
kunjukunjuzz904
 
Ad

More from Rouven Weßling (7)

PDF
Adapting our API for multiple platforms
Rouven Weßling
 
PDF
php[world] 2016 - API Mashup - Combining APIs for Fun and Profit
Rouven Weßling
 
PDF
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
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
 
Adapting our API for multiple platforms
Rouven Weßling
 
php[world] 2016 - API Mashup - Combining APIs for Fun and Profit
Rouven Weßling
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
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
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Import Data Form Excel to Tally Services
Tally xperts
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Tally software_Introduction_Presentation
AditiBansal54083
 

API Days Paris - Automatic Testing of (RESTful) API Documentation

  • 1. Automatic testing of (RESTful) API documentation API Days Paris, December 2016 By Rouven Weßling ( ) Ecosystem Developer / Developer Evangelist, Contentful @RouvenWessling photo credit: byMusée du Louvre Dustin Gaffke (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 beforeAll called at the beginning of the whole test run beforeEach called before each HTTP transaction before called before some specific HTTP transaction beforeEachValidation called before each HTTP transaction is validated beforeValidation called before some specific HTTP transaction is validated after called a er some specific HTTP transaction regardless its result afterEach called a er each HTTP transaction afterAll called 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/api-days- paris-automatic-testing-of-restful-api-documentation Follow me on Twitter: @RouvenWessling