Harnessing BDD Techniques like Example Mapping for Effective API Documentation

A presentation at APIDays Paris in December 2023 in Paris, France by Frank Kilcommins

Slide 1

Slide 1

Harnessing BDD & Example Mapping for effective API delivery #apidays

Slide 2

Slide 2

I’m Frank Kilcommins › › › › Principal API Technical Evangelist @ SmartBear Developer and Architect ( APIs & Developer Experience) Governance Board member on OpenAPI Initiative (OAI) Contributor on Workflows Specification › Connect: @fkilcommins @frank-kilcommins frank.kilcommins@smartbear.com /* insert embarrassing photo here */

Slide 3

Slide 3

Talk Track › › › › Why APIs Fail - The People Problem Leveraging BDD & API Specifications for API delivery Takeaways Q&A

Slide 4

Slide 4

The People Problem… › Organizational challenges Technology focus dominates rather than people and process. (This graphic reflects Integrated Automation but is also true for APIs)

Slide 5

Slide 5

Alignment Gap › Only 48% are confident their APIs are well documented and explain value for consumers Our APIs are well documented for our consumers Agree 38% Neutral 30% Disagree 16% Strongly Agree 10% Strongly Disagree 2023 5% 0% 10% 20% 30% 2021 40% Our organization has good processes in place to ensure APIs can be efficiently consumed › ~43% unsure their processes will deliver appropriate developer experience (DX) Agree 45% Neutral 27% Disagree 12% Strongly Agree 12% Strongly Disagree 2023 2021 4% 0% 5% 10% 15% Source: SmartBear – State of Software Quality | API 2023 20% 25% 30% 35% 40% 45% 50%

Slide 6

Slide 6

Playlist for the modern API program

Slide 7

Slide 7

./BDD for API Delivery BDD for API Delivery

Slide 8

Slide 8

Business Rules Where are the API requirements?

Slide 9

Slide 9

Business Rules Acceptance Criteria Where are the API requirements?

Slide 10

Slide 10

Acceptance Criteria Business Rules Where are the API requirements? Test Plan

Slide 11

Slide 11

Acceptance Criteria Business Rules Where are the API requirements? Test Plan Napkins to Code with annotations

Slide 12

Slide 12

BDD for API Delivery

Slide 13

Slide 13

./API Specifications API Specifications

Slide 14

Slide 14

Popular API related Specifications WSDL | WADL | RAML | API Blueprint

Slide 15

Slide 15

Let Specifications Drive the API Lifecycle Implementation Generated server code / models Mocking Testing Prototyping Functional, security, load, compliance etc. Design Virtualization Reuse, linking, callbacks Functional/Runtime, use-case simulations Clients Documentation Generated libraries Developer Portals, code examples, user guides, support, etc. Deployment/Runtime Security, usage policies, monitoring, caching, rate-limiting, metrics etc.

Slide 16

Slide 16

“Good specifications will always improve programmer productivity far better than any programming tool or technique.” - Milt Bryce

Slide 17

Slide 17

BDD for API Delivery

Slide 18

Slide 18

BDD for API Delivery

Slide 19

Slide 19

BDD for API Delivery

Slide 20

Slide 20

Example Mapping for Deliberate Discovery › Effectively explore and refine detailed acceptance criteria so that: › › › › Agreed the scope Identified as much uncertainty as possible Agreed on the readiness for design/development Identified concrete examples

Slide 21

Slide 21

Example Mapping for Deliberate Discovery › Effectively explore and refine detailed acceptance criteria so that: › › › › Agreed the scope Identified as much uncertainty as possible Agreed on the readiness for design/development Identified concrete examples Unknown unknowns

Slide 22

Slide 22

Example Mapping for Deliberate Discovery › Effectively explore and refine detailed acceptance criteria so that: › › › › Agreed the scope Identified as much uncertainty as possible Agreed on the readiness for design/development Identified concrete examples Unknown unknowns Known unknowns

Slide 23

Slide 23

Example Mapping for Deliberate Discovery › Effectively explore and refine detailed acceptance criteria so that: › › › › Agreed the scope Identified as much uncertainty as possible Agreed on the readiness for design/development Identified concrete examples Unknown unknowns Known unknowns Known knowns

Slide 24

Slide 24

USER STORY RULE EXAMPLE EXAMPLE EXAMPLE RULE RULE EXAMPLE EXAMPLE EXAMPLE QUESTION? ASSUMPTION

Slide 25

Slide 25

Who should participate? The traditional 3 Amigos

Slide 26

Slide 26

Who should participate? API Designer * The traditional 3 Amigos API Architect * Enhanced with API specific SMEs * dedicated or floating from a C4E

Slide 27

Slide 27

Practical API Governance › Are we building the right API? › Are we building the API right?

Slide 28

Slide 28

Creating a Pet Adoption Service Problem: We’re overwhelmed by the number of pets being abandoned at our pet store. Solution: Following research and evaluation, we’ve decided to create the ability to search for and adopt pets that we catalog. We’ll offer the service via our website but also with a wider eco-system of shelters, charities, and pet orphanages. Photo by Thomas Park on Unsplash

Slide 29

Slide 29

Creating a Pet Adoption Service Problem: We’re overwhelmed by the number of pets being abandoned at our pet store. Solution: Following research and evaluation, we’ve decided to create the ability to search for and adopt pets that we catalog. We’ll offer the service via our website but also with a wider eco-system of shelters, charities, and pet orphanages. Photo by Thomas Park on Unsplash

Slide 30

Slide 30

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED

Slide 31

Slide 31

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED

Slide 32

Slide 32

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION

Slide 33

Slide 33

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL PAGED SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION SEARCHING PETS MUST SUPPORT PAGINATION (PAGED RESULTS & PARAMETERS)

Slide 34

Slide 34

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL PAGED SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED JANE SEARCHES FOR ADOPTED STATUS PETS => PAGED SUMMARY OF ADOPTED PETS RETURNED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION SEARCHING PETS MUST SUPPORT PAGINATION (PAGED RESULTS & PARAMETERS)

Slide 35

Slide 35

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL PAGED SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED JANE SEARCHES FOR ADOPTED STATUS PETS => PAGED SUMMARY OF ADOPTED PETS RETURNED JANE SEARCHES FOR PETS LOCATED IN GALWAY => PAGED SUMMARY OF GALWAY LOCATED PETS RETURNED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION SEARCHING PETS MUST SUPPORT PAGINATION (PAGED RESULTS & PARAMETERS)

Slide 36

Slide 36

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL PAGED SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED JANE SEARCHES FOR ADOPTED STATUS PETS => PAGED SUMMARY OF ADOPTED PETS RETURNED JANE SEARCHES FOR PETS LOCATED IN GALWAY => PAGED SUMMARY OF GALWAY LOCATED PETS RETURNED JANE SEARCHES CATS => PAGED SUMMARY OF CATS REGARDLESS OF LOCATION, STATUS, OR BREED RETURNED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION SEARCHING PETS MUST SUPPORT PAGINATION (PAGED RESULTS & PARAMETERS)

Slide 37

Slide 37

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL PAGED SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION JANE SEARCHES FOR ADOPTED STATUS PETS => PAGED SUMMARY OF ADOPTED PETS RETURNED JANE SEARCHES FOR PETS LOCATED IN GALWAY => PAGED SUMMARY OF GALWAY LOCATED PETS RETURNED JANE SEARCHES CATS => PAGED SUMMARY OF CATS REGARDLESS OF LOCATION, STATUS, OR BREED RETURNED JANE SEARCHES FOR BOXER BREED CATS => AN EMPTY RESPONSE IS RETURNED SEARCHING PETS MUST SUPPORT PAGINATION (PAGED RESULTS & PARAMETERS) WHEN CRITERIA DOES NOT MATCH A PET RETURN EMPTY RESPONSE (NOT ERROR)

Slide 38

Slide 38

SEARCH FOR PETS CALLING THE SEARCH PETS RESOURCE RETURNS ALL AVAILABLE PETS JANE CALLS THE SEARCH PETS RESOURCE => ALL PAGED SUMMARY DETAILS OF AVAILABLE PETS ARE RETURNED PETS CAN BE FILTERED BY STATUS, CATEGORY, LOCATION, & BREED A PET SUMMARY SHOULD HAVE: NAME, ID, STATUS, CATEGORY, BREED, LOCATION JANE SEARCHES FOR ADOPTED STATUS PETS => PAGED SUMMARY OF ADOPTED PETS RETURNED JANE SEARCHES FOR PETS LOCATED IN GALWAY => PAGED SUMMARY OF GALWAY LOCATED PETS RETURNED JANE SEARCHES CATS => PAGED SUMMARY OF CATS REGARDLESS OF LOCATION, STATUS, OR BREED RETURNED JANE SEARCHES FOR BOXER BREED CATS => AN EMPTY RESPONSE IS RETURNED SEARCHING PETS MUST SUPPORT PAGINATION (PAGED RESULTS & PARAMETERS) JOE SEARCHES 1 PAGE OF PETS WITH 10 PER PAGE * PAGE PARAMS VALIDATED => A PAGED RESULT CONTAINING 10 PETS WITH LINKS TO NEXT/SELF/PREVIOUS PAGES RETURNED WHEN CRITERIA DOES NOT MATCH A PET RETURN EMPTY RESPONSE (NOT ERROR)

Slide 39

Slide 39

What does formulation look like? Check out: https://www.youtube.com/watch?v=L8HjnzOmhV4

Slide 40

Slide 40

VIEW PET DETAILS THE FULL PET DETAILS CAN BE RETURNED ONCE THE PETID IS KNOWN JANE HAS THE PETID AND USES IT TO GET THE PET DETAILS => FULL DETAILS ON THE PET RETURNED JOE USES THE NAME OF A PET TO GET THE DETAILS => A BAD REQUEST RESPONSE IS RETURNED JOE HAS A PETID BUT IT DOES NOT MATCH A RECORD IN OUR SYSTEM => A NOT FOUND RESPONSE IS RETURNED REQUEST PARAMETERS MUST MATCH THE EXPECTED TYPE OR PATTERN VALID REQUESTS ON SINGULAR RESOURCE NOT MATCHING A RECORD MUST RETURN 404

Slide 41

Slide 41

AUTHENTICATED USERS CAN ADD NEW PETS FOR ADOPTION JANE HAS AN AUTH TOKEN AND SENDS A NEW PET RECORD * REQUEST VALIDATED => A SUCCESSFUL RESPONSE IS RETURN INCLUDING THE PET RESOURCE JOE TRIES TO CREATE A PET BUT FORGETS HIS TOKEN => A UNAUTHORIZED REPONSE RETURNED ADD A NEW PET A NEW PET MUST HAVE AT LEAST NAME, CATEGORY, BREED, AND LOCATION SET JOE SENDS A NEW PET RECORD WITH JUST NAME AND CATEGORY * REQUEST VALIDATION FAILS => A BAD REQUEST IS RETURNED ALWAYS RETURN A HTTP 201 RESPONSE FOR CREATED RESOURCES JOE SENDS A NEW PET RECORD THAT MEETS VALIDATION RULES => A HTTP 201 RESPONSE IS CREATED WHICH ALSO CONTAINS THE PET RECORD ALWAYS RETURN A LOCATION HTTP RESPONSE HEADER FOR CREATED RESOURCES JOE SENDS A NEW PET RECORD THAT MEETS VALIDATION RULES => THE RESPONS CONTAINS A LOCATION HEADER WITH THE LINK TO THE GET /PETS/{ID} ERROR RESPONSES MUST CONFORM TO RFC 7807

Slide 42

Slide 42

ADOPT A PET AVAILABLE PETS CAN BE ADOPTED BY REGISTERED USERS JANE IS REGISTERED AND CHOOSED TO ADOPT AN AVAILABLE PET => THE ADOPTION IS REGISTERED, THE PET STATUS IS UPDATED, AND A CONFIRMATION IS RETURNED TO JANE JOE TRIES TO ADOPT AN ADOPTED PET => AN ERROR IS RETURNED WITH INFO THAT THE PET IS UNAVAILABLE FOR ADOPTION SALLY IS UNREGISTERED AND TRIES TO ADOPT A PET => AN ERROR MESSAGE IS RETURNED TO SALLY AS SHE MUST BE REGISTERED JOE TRIES TO ADOPT AN UNKNOWN PET => A 404 NOT FOUND ERROR IS RETURNED TO JOE SHOULD A 401 UNAUTHORISED OR 403 FORBIDDEN STATUS BE RETURNED FOR UNREGISTERED?

Slide 43

Slide 43

GET PET ADOPTIONS LIST A REGISTERED USER CALLING THE SEARCH ADOPTIONS ALL RECORDED ADOPTIONS JANE IS REGISTERED AND CALLS THE SEARCH ADOPTIONS RESOURCE => PAGED SUMMARY OF ADOPTIONS RETURNED JOE SEARCHES FOR ADOPTIONS BUT OMITS TOKEN => AN UNAUTHORIZED RESPONSE IS RETURNED ADOPTIONS CAN BE FILTERED BY STATUS, AND LOCATION JANE SEARCHES FOR ADOPTIONS WITH PENDING STATUS => PAGED SUMMARY OF PENDING ADOPTIONS RETURNED JOE SEARCHES FOR INACTIVE ADOPTIONS => AN ERROR IS RETURNED AS INVALID IS NOT AN ADOPTION STATUS JOE SEARCHES FOR ADOPTIONS WITH A COLOUR=RED => A PAGED SUMMARY OF ADOPTIONS RETURNED A ADOPTION CAN HAVE STATUS OF REQUESTED, PENDING, AVAILABLE, DENIED, APPROVED UNKNOWN QUERY PARAMETERS SHOULD BE IGNORED

Slide 44

Slide 44

Can we do more with “Examples”?

Slide 45

Slide 45

Most Important API Documentation Features? › Examples continue to be the best learning resource for consumers SmartBear – State of Software Quality | API 2023

Slide 46

Slide 46

Most Important API Documentation Features? › Examples continue to be the best learning resource for consumers SmartBear – State of Software Quality | API 2023

Slide 47

Slide 47

What does example-enriched formulation look like? Check out: https://www.youtube.com/watch?v=L8HjnzOmhV4

Slide 48

Slide 48

Slide 49

Slide 49

Summary › › › › Focus on the consumer and the behaviour they need Keep people at the center of API delivery Human conversations & techniques like example mapping work Collaboration is key to delivering good Developer Experience › Remember: Your API is a promise, let it tell its story!

Slide 50

Slide 50

Thank You! Questions? › Connect: @fkilcommins @frank-kilcommins frank.kilcommins@smartbear.com