Designing a networking layer on URLSession
In a phone screen you're asked to design a simple networking layer in Swift. Without third parties, what types would you put on top of URLSession, and what is each one responsible for?
In a phone screen you're asked to design a simple networking layer in Swift. Without third parties, what types would you put on top of URLSession, and what is each one responsible for?
Three layers are enough: Endpoint (declares path, method, parameters), a generic APIClient (builds the URLRequest, runs it on URLSession, checks the status code, decodes), and a domain error enum. Inject URLSession through a protocol for testing.
ArchitectureShort answerAdvanced
You have three network clients for the auth server, product server, and payment server…
#endpoint #generic
NetworkingShort answerIntro
You've inherited an app that does all its networking through URLSession.shared. Can you…
#urlsession
NetworkingShort answerBasics
You've found network-layer code that collapses every failure into completion(nil). As a…
#error-handling
NetworkingMultiple choiceBasics
Select all the statements that correctly describe HTTP/2 compared with HTTP/1.1.
#urlsession