Upgrade to Pro — share decks privately, control downloads, hide ads and more …

우린 같은 같은 곳을 바라 보고 있나요?

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Arawn Park Arawn Park
November 30, 2022

우린 같은 같은 곳을 바라 보고 있나요?

Let'Swift 2022에서 발표한 "우린 같은 같은 곳을 바라 보고 있나요?" 의 장표입니다.

시간이 흐르면서 망가지는 계약(API)에 대한 고민과 해법에 대한 견해를 공유합니다.

http://letswift.kr/2022/

Avatar for Arawn Park

Arawn Park

November 30, 2022
Tweet

More Decks by Arawn Park

Other Decks in Programming

Transcript

  1. Consumer Provider HTTP Client HTTP Server ਃ୒ 3FRVFTU ਽׹ 3FTQPOTF

    3&45"1*BLB3&45GVMPS8FC"1*PS)551"1* ੗ਗ(RESOURCE) - URI ೯ਤ(Verb) - HTTP Method ಴അ(Representations) )551೐۽ష௒ӝ߈ ਢӝࣿ੉о૓न܉ࢿ ഛ੢ࢿਸӒ؀۽੉য߉ই࠙࢑ஹೊ౴ী੸೤ೠ"1*ٜ݅ࣻ੓חߑߨਵ۽੗ਗ 3&4063$& 63* ೯ਤ 7FSC )551.&5)0% ಴അ 3FQSFTFOUBUJPOT ਵ۽ҳࢿغয੓׮ ࢲ࠺झઁҕ੗੢গա֎౟ਕ௼૑ো١ਸҊ۰೧ঠೠ׮
  2. Consumer Provider RPC Stub RPC Server ਃ୒ 3FRVFTU ਽׹ 3FTQPOTF

    Shared Library ਗѺ೐۽द੷ഐ୹3FNPUF1SPDFEVSF$BMM31$ ۽ஸ೐۽द੷աݫࣗ٘ܳഐ୹ೞ٠ਗѺदझమীࢲ࠺झܳࢎਊೡࣻ੓חߑߨਵ۽֎౟ਕ௼ܳ੉ਊೠ׮חੋ૑بহ੉ਗѺदझమীࢲ࠺झܳऔѱా೤ೞҊ ࢎਊೡࣻ੓׮ ೞ૑݅فदझమръѾ೤੉ੌযդ׮য়ېػӝࣿэ૑݅ҳӖীࢲҕѐೠH31$੄҃਋ъ۱ೠࢿמҗ׮নೠ೒ۖಬਸ૑ਗೞחبҳ۽୭Ӕ௾ҙबਸ੉ՑҊ੓׮
  3. Tech spec IDL repo swift code kotlin code etc go/python/..

    Generator "1*ݺࣁ۽௏٘ࢤࢿೞӝ
  4. ❯ create-api generate schema.json --config-option module=PetstoreKit --output PetstoreKit Generating code

    for schema.json... import Foundation import Get import PetstoreKit public class PetstoreWebClient { let api: APIClient public init() { self.api = APIClient( baseURL: URL(string: "https://letswift.kr/2022/petstore") ) } public func findPets(by status: Paths.Pet.FindByStatus.Status) async throws -> [Pet] { let request = Paths.pet.findByStatus.get(status: status) let response = try await api.send(request) return response.value } } IDL repo swift package CreateAPI $SFBUF"1*۽4XJGU௏٘ࢤࢿೞӝ ① Using the Code ②
  5. import Foundation import PetstoreKit import SwiftGRPC public class PetstoreGrpcClient {

    let client: PetstoreServiceClient public init() { self.client = PetstoreServiceClient.init( address: "letswift.kr:80", secure: false ) } public func findPets(by status: FindPetsByStatusRequestStatus) async throws -> [Pet] { let request = FindPetsByStatusRequest.init(status: status) let response = try await client.findPetsByStatus(request) return response.pets } } IDL repo petstore.grpc.swift, petsotre.pb.swift gRPC Swift H31$۽4XJGU௏٘ࢤࢿೞӝ Using the Code ② ❯ protoc schema.proto \ --swift_out=Visibility=Public:./PetstoreKit/Sources --grpc-swift_out=Visibility=Public,Client=true,Server=false:./PetstoreKit/Sources ①
  6. Client GraphQL API { "user": { "id": 2022, "name": "Arawn

    Park", "address": { "city": "Firenze", "street": "Piazza del Duomo" } } } query { user (id: 2022) { id name address { city street } } } HTTP Request HTTP Response ௪ܻझః݃ഛੋ੉оמೠ(SBQI2-
  7. Consumer Provider Unit tests Unit tests Required interactions are captured

    into a contract between systems Contract is shared amongst teams to enable collaboration, using tools like Pactflow Requests in contract replayed against provider API and verified against consumer s expectations Consumer unit tests its behaviour against provider mock Provider tests mock out any other systems, so it can be tested in isolation ① ② ③ ④ ⑤ ҅ডపझ౟$POUSBDU5FTU ೞӝ
  8. 1BDUGMPX۽ೞח҅ডపझ౟ Consumer Provider Ý GET /users/2022 { "user": { "id":

    2022, "name": "Arawn Park" } } GET /users/2022 { "user": { "id": 2022, "name": "Arawn Park" } } Testing a consumer using a Pact mock provider ① mock provider simulated consumer Testing a provider using a Pact simulated consumer ② Contract
  9. ଵҊ੗ܐ - The Design of Web APIs - Create API

    - gRPC Swift - Next Generation Client APIs in Envoy Mobile - Move Fast and Consumer Driven Contract Test Things - How Pact contract testing works