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

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

Alexander Tamoykin

August 03, 2017
Tweet

More Decks by Alexander Tamoykin

Other Decks in Technology

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. A P P S A R E A P I

    P O W E R E D
  5. 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
  6. 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
  7. 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
  8. 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)) ... }
  9. 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) }
  10. A P I E R R O R enum BackEndAPIError:

    Error { case missingData case mockConfiguration case other(error: Error) }
  11. 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 } }
  12. 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)) } }
  13. 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)) } }
  14. 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 } } }
  15. S H O U L D Y O U U

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

    O J E C T S
  17. W H AT W E C O V E R

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

    M AT T E R S M O S T
  19. 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