SlideShare uma empresa Scribd logo
1 de 25
- documentation and testing using Swagger and Pact
Coherent REST
API design
2.
Contact Information
Frederik Mogensen
Software Developer, Cloud Team
Stibo Systems
E: frmo@stibosystems.com
L: linkedin.com/in/fmogensen
3.
Agenda
 Contract driven API design
 Provider contracts - with Swagger
 Consumer Driven contracts - with Pact
1
Contract drivenAPI design
5.
APIs in a Microservice architecture
 Unstable / changingAPIs
 No type safety between services
 No developer confidence
2
Provider contracts
- with Swagger
 “ A Provider Contract is a
description of a service offered by a
provider”
 - Steven Smith
 https://dzone.com/articles/application-pattern-consumer
7.
Swagger Example The Petstore
paths:
'/pet/’:
post:
tags:
- pet
description: Add a new pet to the store
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description:Pet object that needs to be added to the store
required:true
schema:
$ref: '#/definitions/Pet‘
responses:
'405':
description:Invalid input
'200':
description:successful operation
'/pet/{petId}':
get:
tags:
- pet
summary:Find pet by ID
produces:
- application/json
parameters:
- name: petId
in: path
description:ID of pet to return
required:true
type: integer
responses:
'200':
description:successful operation
schema:
$ref: '#/definitions/Pet'
'404':
description:Pet not found
security:
- api_key: []
8.
Why define service endpoints?
 API that are JSON first
 Documentation and clarity
 Server / Client code generation
9.
Iterative API first development
Update
Swagger
Definition
Generate
Endpoints
Implement
functionality
Test and
validate API
New demands
for API
10.
Demo using Swagger and Postman
3
Consumer-Driven contracts
- with Pact
 “ A Consumer Driven Contract is a
description of how a provider satisfies an
aggregate of Consumer Contracts ”
 - Steven Smith
 https://dzone.com/articles/application-pattern-consumer
12.
Integration test in a Microservice architecture
Characteristic
 Slow
 Easy to break
 Hard to fix
 Scales BADLY
 Lots of infrastructure
 Lots of set up
 False negatives
Infrastructure
 Startup all services
 Populate Databases
 Mock away external
services
http://www.slideshare.net/bethesque/pact-44565612
13.
Pact tests
Characteristic
 Fast
 Stable
 Easy to debug
 Reliable
 No extra infrastructure
 Low setup
 Scales linearly
Contracts for only the needed stuff
Consumer-driven contracts describes the complete set of functionality
demanded by the current set of consumers.
http://www.slideshare.net/bethesque/pact-44565612
14.
Pacts – The basics
Consumer Provider
Request
Response
http://www.slideshare.net/bethesque/pact-44565612
15.
Pacts – The basics
Consumer Provider
Request
Response
Request
Response
Pact
Consumer
Provider
http://www.slideshare.net/bethesque/pact-44565612
16.
Pact Example
Pact Broker
Mapping
Pact
Frontend
Mapping
Product
Pact
Mapping
Product
Login
Pact
Frontend
Login
Datastandard
Pact
Mapping
Datastandard
User
Pact
Login
User
Pact
iPhone
Login
17.
Pact Broker
Mapping
Pact
Frontend
Mapping
Product
Pact
Mapping
Product
Login
Pact
Frontend
Login
Datastandard
Pact
Mapping
Datastandard
User
Pact
Login
User
Pact
iPhone
Login
Pact Example
Consumer publishes
pact on build
Provider gets all pacts
from broker - on test
18.
Defining a Pact
@Pact(provider = "Datastandard", consumer = "Mapping")
public PactFragment createFragment(PactDslWithProvider builder) {
return builder
.given("datastandard-default")
.uponReceiving("A request for category with id=1 in specific datastandard")
.path("/dataStandards/dataId/categories/1")
.method("GET")
.willRespondWith()
.status(200)
.body( "{" +
""id": "1"," +
""name": "Toys"" +
"}" )
.toFragment();
}
Pact
Consumer
Provider
http://www.slideshare.net/bethesque/pact-44565612
19.
Pact example
{
"consumer": { "name": "Mapping" },
"provider": { "name": "Datastandard" },
"interactions": [
{
"producer_state": "datastandard-default",
"description": "A request for category with id=1 in specific datastandard",
"request": {
"method": "get",
"path": "/dataStandards/dataId/categories/1"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": "1",
"name": "Toys"
}
}
}
],
"metadata": {
"pactSpecificationVersion": "1.0.0"
}
}
Pact
Consumer
Provider
20.
Validating Pact on Consumer side
@Rule
public PactProviderRule rule = new PactProviderRule("Datastandard","localhost",“1234",this);
@Test
@PactVerification("Datastandard")
public void runTest() {
// Path variables
String datastandardId = "dataId";
String categoryId = "1";
DatastandardService datastandardService = new DatastandardService("http://localhost:1234");
Category category = datastandardService.getCategory(datastandardId, categoryId);
Category expectedCategory =
new Category().withId("1").withName("Toys");
Assert.assertEquals(expectedCategory, category);
}
Consumer
Request
Response
Pact
Consumer
Provider
http://www.slideshare.net/bethesque/pact-44565612
21.
Validating Pact on Provider side
@RunWith(PactRunner.class)
@SpringApplicationConfiguration(classes = LeapDataStandardApplication.class)
@ContextConfiguration(classes = TestAppConfig.class)
@PactBroker(BrokerProtocol = "http", BrokerHost = "docker-machine",
BrokerPort = "80", ProviderName = "Datastandard")
public class DatastandardControllerTest {
@Autowired
private DataStandardController apiController;
private DataStandardDelegateController delegateController =
mock(DataStandardDelegateController.class, Mockito.RETURNS_SMART_NULLS);
@Before
public void setUp() throws Exception {
ReflectionTestUtils.setField(apiController, "delegate", delegateController);
}
@ProviderState(value = "datastandard-default", deferredResponseInMillis = 0)
public DataStandardController shouldResponseCorrectForDefaultDataSet() {
when(delegateController.getStandardCategory( eq("dataId"), eq("1") ))
.thenReturn(new ResponseEntity<>(
new Category().withId("1").withName("Toys"), HttpStatus.OK));
return apiController;
}
}
Provider
Request
Response
Pact
Consumer
Provider
http://www.slideshare.net/bethesque/pact-44565612
22.
Problems that can be detected with Pact
 Change of the endpoint URL
 Change in the expected parameters
 Change in the response payload
23.
What is it not good for?
 Performance and load testing.
 Functional testing of the provider
 Should be done by provider's own tests
Pact is about checking the contents and
format of requests and responses.
Questions and Comments
25.
References, documentation and more…
 github.com/realestate-com-au/pact
 martinfowler.com/articles/consumerDrivenContracts.html
 slideshare.net/bethesque/pact-44565612
 slideshare.net/evanbottcher/from-monoliths-to-microservices-at-
realestatecomau
 techblog.newsweaver.com/why-should-you-use-consumer-driven-
contracts-for-microservices-integration-tests/
 dzone.com/articles/application-pattern-consumer

Mais conteúdo relacionado

Destaque

Destaque (20)

Apis - A Cola que todos deveriam conhecer.
Apis - A Cola que todos deveriam conhecer.Apis - A Cola que todos deveriam conhecer.
Apis - A Cola que todos deveriam conhecer.
 
Apresentação rest api
Apresentação rest apiApresentação rest api
Apresentação rest api
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptx
 
Autoscalable open API testing
Autoscalable open API testingAutoscalable open API testing
Autoscalable open API testing
 
Dominando o customizer
Dominando o customizerDominando o customizer
Dominando o customizer
 
Expondo APIs de back-ends legados e travados
Expondo APIs de back-ends legados e travadosExpondo APIs de back-ends legados e travados
Expondo APIs de back-ends legados e travados
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web services
 
Heleen Kuipers - presentatie reinventing organisations
Heleen Kuipers - presentatie reinventing organisationsHeleen Kuipers - presentatie reinventing organisations
Heleen Kuipers - presentatie reinventing organisations
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat Application
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
 
Repensando o ESB: sua arquitetura SOA, usando APIs
Repensando o ESB: sua arquitetura SOA, usando APIsRepensando o ESB: sua arquitetura SOA, usando APIs
Repensando o ESB: sua arquitetura SOA, usando APIs
 
Rest assured
Rest assuredRest assured
Rest assured
 
Continuous Delivery Testing @HiQ
Continuous Delivery Testing @HiQContinuous Delivery Testing @HiQ
Continuous Delivery Testing @HiQ
 
Auto-scaled Concourse CI on AWS w/o BOSH
Auto-scaled Concourse CI on AWS w/o BOSHAuto-scaled Concourse CI on AWS w/o BOSH
Auto-scaled Concourse CI on AWS w/o BOSH
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
testng
testngtestng
testng
 
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWERContinuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
 
Api testing
Api testingApi testing
Api testing
 

Semelhante a Coherent REST API design

Semelhante a Coherent REST API design (20)

Contract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiDContract testing | Евгений Кузьмин | CODEiD
Contract testing | Евгений Кузьмин | CODEiD
 
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
Contract testing. Isolated testing of microservices with pact.io - Evgeniy Ku...
 
Contract testing and Pact
Contract testing and PactContract testing and Pact
Contract testing and Pact
 
Software contracts - Global Enterprise Agile 2023.pdf
Software contracts - Global Enterprise Agile 2023.pdfSoftware contracts - Global Enterprise Agile 2023.pdf
Software contracts - Global Enterprise Agile 2023.pdf
 
Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)
 
Consumer-Driven Contract Testing
Consumer-Driven Contract TestingConsumer-Driven Contract Testing
Consumer-Driven Contract Testing
 
Z101666 best practices for delivering hybrid cloud capability with apis
Z101666 best practices for delivering hybrid cloud capability with apisZ101666 best practices for delivering hybrid cloud capability with apis
Z101666 best practices for delivering hybrid cloud capability with apis
 
[WSO2Con EU 2018] Blockchain in the Business API Ecosystem - API Consumption ...
[WSO2Con EU 2018] Blockchain in the Business API Ecosystem - API Consumption ...[WSO2Con EU 2018] Blockchain in the Business API Ecosystem - API Consumption ...
[WSO2Con EU 2018] Blockchain in the Business API Ecosystem - API Consumption ...
 
Consumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureConsumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice Architecture
 
Consumer driven contracts in java world
Consumer driven contracts in java worldConsumer driven contracts in java world
Consumer driven contracts in java world
 
SVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApiSVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApi
 
Consumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureConsumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice Architecture
 
What API Specifications and Tools Help Engineers to Construct a High-Security...
What API Specifications and Tools Help Engineers to Construct a High-Security...What API Specifications and Tools Help Engineers to Construct a High-Security...
What API Specifications and Tools Help Engineers to Construct a High-Security...
 
Micro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsMicro-service delivery - without the pitfalls
Micro-service delivery - without the pitfalls
 
Vistex Contract Overview
Vistex Contract OverviewVistex Contract Overview
Vistex Contract Overview
 
TDD for Microservices
TDD for MicroservicesTDD for Microservices
TDD for Microservices
 
Contract Testing
Contract TestingContract Testing
Contract Testing
 
Mastering the api hell
Mastering the api hellMastering the api hell
Mastering the api hell
 
Contract testing - Sealights 2022.pdf
Contract testing - Sealights 2022.pdfContract testing - Sealights 2022.pdf
Contract testing - Sealights 2022.pdf
 
AppGate Getting Started Resources for Telarus Partners
AppGate Getting Started Resources for Telarus PartnersAppGate Getting Started Resources for Telarus Partners
AppGate Getting Started Resources for Telarus Partners
 

Último

Último (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Coherent REST API design

  • 1. - documentation and testing using Swagger and Pact Coherent REST API design
  • 2. 2. Contact Information Frederik Mogensen Software Developer, Cloud Team Stibo Systems E: frmo@stibosystems.com L: linkedin.com/in/fmogensen
  • 3. 3. Agenda  Contract driven API design  Provider contracts - with Swagger  Consumer Driven contracts - with Pact
  • 5. 5. APIs in a Microservice architecture  Unstable / changingAPIs  No type safety between services  No developer confidence
  • 6. 2 Provider contracts - with Swagger  “ A Provider Contract is a description of a service offered by a provider”  - Steven Smith  https://dzone.com/articles/application-pattern-consumer
  • 7. 7. Swagger Example The Petstore paths: '/pet/’: post: tags: - pet description: Add a new pet to the store consumes: - application/json produces: - application/json parameters: - in: body name: body description:Pet object that needs to be added to the store required:true schema: $ref: '#/definitions/Pet‘ responses: '405': description:Invalid input '200': description:successful operation '/pet/{petId}': get: tags: - pet summary:Find pet by ID produces: - application/json parameters: - name: petId in: path description:ID of pet to return required:true type: integer responses: '200': description:successful operation schema: $ref: '#/definitions/Pet' '404': description:Pet not found security: - api_key: []
  • 8. 8. Why define service endpoints?  API that are JSON first  Documentation and clarity  Server / Client code generation
  • 9. 9. Iterative API first development Update Swagger Definition Generate Endpoints Implement functionality Test and validate API New demands for API
  • 10. 10. Demo using Swagger and Postman
  • 11. 3 Consumer-Driven contracts - with Pact  “ A Consumer Driven Contract is a description of how a provider satisfies an aggregate of Consumer Contracts ”  - Steven Smith  https://dzone.com/articles/application-pattern-consumer
  • 12. 12. Integration test in a Microservice architecture Characteristic  Slow  Easy to break  Hard to fix  Scales BADLY  Lots of infrastructure  Lots of set up  False negatives Infrastructure  Startup all services  Populate Databases  Mock away external services http://www.slideshare.net/bethesque/pact-44565612
  • 13. 13. Pact tests Characteristic  Fast  Stable  Easy to debug  Reliable  No extra infrastructure  Low setup  Scales linearly Contracts for only the needed stuff Consumer-driven contracts describes the complete set of functionality demanded by the current set of consumers. http://www.slideshare.net/bethesque/pact-44565612
  • 14. 14. Pacts – The basics Consumer Provider Request Response http://www.slideshare.net/bethesque/pact-44565612
  • 15. 15. Pacts – The basics Consumer Provider Request Response Request Response Pact Consumer Provider http://www.slideshare.net/bethesque/pact-44565612
  • 18. 18. Defining a Pact @Pact(provider = "Datastandard", consumer = "Mapping") public PactFragment createFragment(PactDslWithProvider builder) { return builder .given("datastandard-default") .uponReceiving("A request for category with id=1 in specific datastandard") .path("/dataStandards/dataId/categories/1") .method("GET") .willRespondWith() .status(200) .body( "{" + ""id": "1"," + ""name": "Toys"" + "}" ) .toFragment(); } Pact Consumer Provider http://www.slideshare.net/bethesque/pact-44565612
  • 19. 19. Pact example { "consumer": { "name": "Mapping" }, "provider": { "name": "Datastandard" }, "interactions": [ { "producer_state": "datastandard-default", "description": "A request for category with id=1 in specific datastandard", "request": { "method": "get", "path": "/dataStandards/dataId/categories/1" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "id": "1", "name": "Toys" } } } ], "metadata": { "pactSpecificationVersion": "1.0.0" } } Pact Consumer Provider
  • 20. 20. Validating Pact on Consumer side @Rule public PactProviderRule rule = new PactProviderRule("Datastandard","localhost",“1234",this); @Test @PactVerification("Datastandard") public void runTest() { // Path variables String datastandardId = "dataId"; String categoryId = "1"; DatastandardService datastandardService = new DatastandardService("http://localhost:1234"); Category category = datastandardService.getCategory(datastandardId, categoryId); Category expectedCategory = new Category().withId("1").withName("Toys"); Assert.assertEquals(expectedCategory, category); } Consumer Request Response Pact Consumer Provider http://www.slideshare.net/bethesque/pact-44565612
  • 21. 21. Validating Pact on Provider side @RunWith(PactRunner.class) @SpringApplicationConfiguration(classes = LeapDataStandardApplication.class) @ContextConfiguration(classes = TestAppConfig.class) @PactBroker(BrokerProtocol = "http", BrokerHost = "docker-machine", BrokerPort = "80", ProviderName = "Datastandard") public class DatastandardControllerTest { @Autowired private DataStandardController apiController; private DataStandardDelegateController delegateController = mock(DataStandardDelegateController.class, Mockito.RETURNS_SMART_NULLS); @Before public void setUp() throws Exception { ReflectionTestUtils.setField(apiController, "delegate", delegateController); } @ProviderState(value = "datastandard-default", deferredResponseInMillis = 0) public DataStandardController shouldResponseCorrectForDefaultDataSet() { when(delegateController.getStandardCategory( eq("dataId"), eq("1") )) .thenReturn(new ResponseEntity<>( new Category().withId("1").withName("Toys"), HttpStatus.OK)); return apiController; } } Provider Request Response Pact Consumer Provider http://www.slideshare.net/bethesque/pact-44565612
  • 22. 22. Problems that can be detected with Pact  Change of the endpoint URL  Change in the expected parameters  Change in the response payload
  • 23. 23. What is it not good for?  Performance and load testing.  Functional testing of the provider  Should be done by provider's own tests Pact is about checking the contents and format of requests and responses.
  • 25. 25. References, documentation and more…  github.com/realestate-com-au/pact  martinfowler.com/articles/consumerDrivenContracts.html  slideshare.net/bethesque/pact-44565612  slideshare.net/evanbottcher/from-monoliths-to-microservices-at- realestatecomau  techblog.newsweaver.com/why-should-you-use-consumer-driven- contracts-for-microservices-integration-tests/  dzone.com/articles/application-pattern-consumer

Notas do Editor

  1. In this talk we look at using Swagger and Pact to handle REST API specifications and contracts. Swagger allows for a JSON first specification of the API as well as generating and discovering service controllers. This can be done coherently across multiple technology stacks. We will look into using Pact to create consumer driven contract between services in a micro service architecture to improve development confidence.
  2. Different consumers of services -> JSON / XML Ever evolving microservices we need to change the API Problem senario 1. Provider service is being updated to a new version 2. It is behaving perfectly 3. But suddenly a number of other services start behaving incorrectly
  3. JSON FIRST: Not just what ever the given framework produces at a given time CODE GEN: Server - Java - C# - C - Ruby - Node - PHP Client - Android - Java - Dart - Perl - Akka scala - Swift - Ruby
  4. http://Docker-machine/api/v1/excel/swagger-ui.html http://docker-machine/api/v1/excel/v2/api-docs
  5. 1. The consumer defines what it expects from a specific request to a service 2. The provider and the consumer agree on this contract 3. The provider continuously verifies that the contract is fulfilled
  6. E.g. renamed endpoints E.g. new mandatory fields Returns an array, instead of having an array wrapped in an object Clearly API-breaking changes. May not be obvious that a code change changes the API. - Renamed Class / Field that are later JSON serialized It may also not be clear which Consumers are affected by code changes.