Collaborative Contract Driven Development Billy Korando Developer - - PowerPoint PPT Presentation

collaborative contract driven development
SMART_READER_LITE
LIVE PREVIEW

Collaborative Contract Driven Development Billy Korando Developer - - PowerPoint PPT Presentation

Collaborative Contract Driven Development Billy Korando Developer Advocate - IBM @BillyKorando william.korando@ibm.com Subscribe to the Java Newsletter https://developer.ibm.com/newsletters/java/ For your Spring & JakartaEE needs


slide-1
SLIDE 1

Collaborative Contract Driven Development

Billy Korando Developer Advocate - IBM @BillyKorando william.korando@ibm.com 📭

slide-2
SLIDE 2

@BillyKorando

Subscribe to the Java Newsletter

https://developer.ibm.com/newsletters/java/

For your Spring & JakartaEE needs

https://cloud.ibm.com/docs/java

slide-3
SLIDE 3

@BillyKorando

https://billykorando.com/

slide-4
SLIDE 4

@BillyKorando

CONTRACT DRIVEN DEVELOPMENT DEFINED

(BRIEFLY)

slide-5
SLIDE 5

@BillyKorando

DEFINING THE BEHAVIOR OF AN API

SERVICE CLIENT

Response: 200 { … } Request /api/… { … }

slide-6
SLIDE 6

@BillyKorando

DECONSTRUCTING THE STATUS QUO (i.e. WHY DEVELOPMENT IS DIFFICULT WITHOUT CONTRACTS)

slide-7
SLIDE 7

@BillyKorando

POORLY DEFINED SERVICES

slide-8
SLIDE 8

@BillyKorando

POORLY DEFINED SERVICES

slide-9
SLIDE 9

@BillyKorando

SCENE BREAKDOWN

  • Poorly defined or undocumented API
  • Inconsistent behavior or patterns
  • Testing against a live service can lead to inconsistent results
slide-10
SLIDE 10

@BillyKorando

VERY SERIAL DEVELOPMENT

slide-11
SLIDE 11

@BillyKorando

VERY SERIAL DEVELOPMENT

slide-12
SLIDE 12

@BillyKorando

SCENE BREAKDOWN

  • Inability to develop in parallel
  • Timeline impacted by delays from both service and client developers
  • Client developer will have to get back up to speed
slide-13
SLIDE 13

@BillyKorando

I AM ALTERING THE API

slide-14
SLIDE 14

@BillyKorando

I AM ALTERING THE API

slide-15
SLIDE 15

@BillyKorando

SCENE BREAKDOWN

  • Breaking API changes not caught until production
  • API design governed almost entirely by service developer
slide-16
SLIDE 16

@BillyKorando

CONTRACT DRIVEN DEVELOPMENT EXPLAINED

USING SPRING CLOUD CONTRACT

slide-17
SLIDE 17

@BillyKorando

SPRING CLOUD CONTRACT

  • Very active project
  • Inter-operable with other tools/standards: OpenAPI, Packt, Swagger
  • Flexible documentation support with Spring REST Docs
  • Polyglot support

More: https://spring.io/projects/spring-cloud-contract

slide-18
SLIDE 18

@BillyKorando

WRITING THE CONTRACT

Contract.make { label “Add New Person” request { method 'POST' url '/api/persons' body([ fName: “John” lName: “Doe”]) headers { header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)} } response { status 201 headers { header(HttpHeaders.LOCATION, 'api/persons/1')} } }

slide-19
SLIDE 19

@BillyKorando

VALIDATING THE CONTRACT

Add New Person Service

slide-20
SLIDE 20

@BillyKorando

SHARING THE CONTRACT Stubs Artifact

slide-21
SLIDE 21

@BillyKorando

SHARING THE CONTRACT Artifact Repository Stubs Artifact

slide-22
SLIDE 22

@BillyKorando

DOCUMENTING THE API

slide-23
SLIDE 23

@BillyKorando

VALIDATING AGAINST THE CONTRACT Stubs Artifact Client

slide-24
SLIDE 24

@BillyKorando

CONTRACT DRIVEN DEVELOPMENT IN REVIEW

  • 1. Write contract(s) to define API behavior
  • 2. Contracts validate API matches behavior
  • 3. Bundle contracts as shareable artifact
  • 4. Generate documentation from contracts
  • 5. Clients can test/develop against artifact}

Automated

slide-25
SLIDE 25

@BillyKorando

slide-26
SLIDE 26

@BillyKorando

PRODUCER DRIVEN CONTRACTS THE API WILL LOOK LIKE THIS

OK

SERVICE CLIENT

slide-27
SLIDE 27

@BillyKorando

CONSUMER DRIVEN CONTRACTS

OK

I NEED THIS FROM THE SERVICE SERVICE CLIENT

slide-28
SLIDE 28

@BillyKorando

WHY COLLABORATION IS IMPORTANT

  • Better utilization of developer time
  • More input from parties on API design
  • More buy-in from parties on API design
slide-29
SLIDE 29

@BillyKorando

CAN’T SPELL “COLLABORATIVE” WITHOUT “POLYGLOT”

slide-30
SLIDE 30

@BillyKorando

Javascript Developers JDK Maven Java friendly IDE Docker Text editor Java Developers JDK Maven Java friendly IDE Docker Text editor Other Developers JDK Maven Java friendly IDE Docker Text editor ✅ ✅ ✅ ✅ ✅ ❌ ❌ ❌ ✅ ✅ ❌ ❌ ❌ ✅ ✅ LANGUAGE INDEPENDENT TOOLS

slide-31
SLIDE 31

@BillyKorando

YAML CONTRACT

request: label: “Add New Person” method: POST url: /api/persons body: fName: “John” lName: “Doe” headers: Content-Type: application/json response: status: 201 headers: Location: api/persons/1

slide-32
SLIDE 32

@BillyKorando

DOCKER IMAGES FOR READING CONTRACTS

  • Encapsulates all Java and Spring Cloud Contract logic within a Docker container
  • Images for both consumers and producers
  • Configured by passing in environment variables
  • Example of using producer image link
  • Example of using consumer image link
slide-33
SLIDE 33

@BillyKorando

CONTRACT TESTING WITH DOCKER Client

Stubs Artifact

slide-34
SLIDE 34

@BillyKorando

Service

CONTRACT TESTING WITH DOCKER

slide-35
SLIDE 35

DEMO TIME!

slide-36
SLIDE 36

@BillyKorando

POORLY DEFINED SERVICES

X

slide-37
SLIDE 37

@BillyKorando

SCENE BREAKDOWN

  • API is documented automatically as a result of the process
  • Accurate documentation encourages discussion on design/consistency
  • Clients can develop/test against contracts which give consistent results
slide-38
SLIDE 38

@BillyKorando

VERY SERIAL DEVELOPMENT

X

slide-39
SLIDE 39

@BillyKorando

SCENE BREAKDOWN

  • Client and service developers can work in parallel once contract is written
  • Process encourages discussion on API design
slide-40
SLIDE 40

@BillyKorando

I AM ALTERING THE API

X

slide-41
SLIDE 41

@BillyKorando

SCENE BREAKDOWN

  • API is checked as part of build process
  • Changes will cause either service or client to fail
  • Prevents “rogue” changes from reaching PROD and becoming “finalized”
slide-42
SLIDE 42

@BillyKorando

FINAL POINTS

  • Not just REST/HTTP

, can also write contracts for messages

  • It’s ok to change contracts
  • Contract tests are not acceptance tests nor replace end-to-end tests

○ Not tested: ■ Resiliency ■ Timeout ■ Performance ■ Edge cases

slide-43
SLIDE 43

@BillyKorando

Q & A

slide-44
SLIDE 44

@BillyKorando

SOURCES Code: https://github.com/wkorando/collaborative-contract-driven-development-2-0 https://cloud.spring.io/spring-cloud-contract/single/spring-cloud-contract.html https://spring.io/blog/2018/02/13/spring-cloud-contract-in-a-polyglot-world Contact me: Twitter: @BillyKorando Email: William.Korando@ibm.com