Build Mobile Apps Faster with AWS API Gateway

Build Mobile Apps Faster with AWS API Gateway

Most of the apps are powered by JSON API. As developers, we sometimes spend 25% to 50% of our time on writing networking code, making requests and parsing JSON. Wouldn't it be nice to not worry about it and focus on fun and engaging UI instead? This is where AWS API Gateway comes in. With API Gateway, you can define your API in one place, export a native Swift SDK and use it in your app without writing custom code. After watching this talk, you'll be able to integrate AWS API Gateway into your app and forget about JSON parsing altogether.

Subscribe to Alex's Blog: https://alextamoykin.com
Connect with Alex on LinkedIn: https://www.linkedin.com/in/alextamoykin/
Blog Post: https://bitly.com/api-gateway-talk
Follow Alex on Twitter: https://twitter.com/fsproru
Presented at the CocoaHeads LA meetup: https://www.meetup.com/CocoaHeads-LA/events/241390659/
Video: https://youtu.be/WZyiLTgmmzc

36b118e795c80c058d942b7af047ea67?s=128

Alexander Tamoykin

August 03, 2017
Tweet

Transcript

  1. B U I L D M O B I L

    E A P P S FA S T E R W I T H A W S A P I G AT E WAY H T T P S : / / A L E X TA M O Y K I N . C O M
  2. A L E X TA M O Y K I

    N F O R M E R LY: A W E S O M E N E S S T V / D R E A M W O R K S , V I C T O R I O U S , Z E S T F I N A N C E C T O @ S H U T T L E F I N A N C E C O - O R G A N I Z E R : C O C O A H E A D S L A L O V E
  3. A G E N D A • W H Y

    • W H AT 
 • H O W
  4. W H Y L E T ’ S S TA

    R T W I T H
  5. A P P S A R E A P I

    P O W E R E D
  6. T Y P I C A L N E T

    W O R K A R C H I T E C T U R E Request Model From JSON View Controller Back End iOS
  7. S I M P L I F I E D

    N E T W O R K A R C H I T E C T U R E View Controller Back End iOS Generated API Gateway Package
  8. W H AT

  9. A W S A P I G AT E WAY

    S E R V I C E S E R V I C E S E R V I C E S E R V I C E API Gateway
  10. H O W I T L O O K S

  11. G E N E R AT E S D K

  12. H O W

  13. B A C K E N D A P I

    P R O T O C O L protocol BackEndAPIType { func createUser( name: String, completion: @escaping ((NetworkResult<User>) -> Void)) ... }
  14. N E T W O R K R E S

    U LT enum BackEndAPIError: Error { case missingData case mockConfiguration case other(error: Error) } enum NetworkResult<ModelResult> { case success(ModelResult) case failure(BackEndAPIError) }
  15. A P I E R R O R enum BackEndAPIError:

    Error { case missingData case mockConfiguration case other(error: Error) }
  16. L I V E B A C K E N

    D I N I T I A L I Z E R class LiveBackEndAPI: BackEndAPIType { let client: MyBackEndAPIClient init(apiKey: String? = nil, baseURL: URL? = nil, client: MyBackEndAPIClient = MyBackEndAPIClient.default()) { self.client = client if let apiKey = apiKey { self.client.apiKey = apiKey } if let baseURL = baseURL { let endpoint = AWSEndpoint(region: client.configuration.regionType, service: .APIGateway, url: baseURL) self.client.configuration.baseURL = baseURL self.client.configuration.endpoint = endpoint } }
  17. L I V E B A C K E N

    D I M P L E M E N TAT I O N func createUser(name: String, completion: @escaping ((NetworkResult<User>) -> Void)) { client.userPost(name: name).continueWith { task in self.processExpectingData(task: task, completion: completion) return nil } } private private func processExpectingData<Model>(task: AWSTask<Model>, completion: ((NetworkResult<Model>) -> Void)) { if let error = task.error { completion(.failure(.other(error: error))) } else if let result = task.result { completion(.success(result)) } else { completion(.failure(.missingData)) } }
  18. M O C K B A C K E N

    D class MockBackEndAPI: BackEndAPIType { func createUser(name: String, completion: @escaping ((NetworkResult<User>) -> Void)) { completeWithMockUser(name: name, completion: completion) } private func completeWithMockUser(name: String, completion: ((NetworkResult<User>) -> Void)) { guard let user = User() else { assertionFailure("Failed to create a mock version of a model. Make sure the mock models are used correctly.") completion(.failure(.mockConfiguration)) return } user.name = name completion(.success(user)) } }
  19. D E FA U LT A P I struct BackEndAPI

    { static let APIKey = "super_secure_key" static let baseURL = URL(string: "https:// api.example.com") static var defaultAPI: BackEndAPIType { if ProcessInfo.isRunningTests { return MockBackEndAPI() } else { let liveBackEnd = LiveBackEndAPI(apiKey: APIKey, baseURL: baseURL) return liveBackEnd } } }
  20. A N D T H AT ’ S I T

  21. S H O U L D Y O U U

    S E I T ? I T D E P E N D S
  22. E X I S T I N G P R

    O J E C T S
  23. N E W P R O J E C T

    S
  24. W H AT W E C O V E R

    E D • W H Y • W H AT 
 • H O W
  25. F O C U S O N W H AT

    M AT T E R S M O S T
  26. G R A C I A S H T T

    P S : / / A L E X TA M O Y K I N . C O M @ F S P R O R U