Last active
February 28, 2022 19:44
-
-
Save adamzarn/f5049d5b775ebdf077b22556f09f4a4a to your computer and use it in GitHub Desktop.
A template for an Endpoint enum that implements URLRequestConvertible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum Endpoint: URLRequestConvertible { | |
case one | |
case two | |
case three | |
var baseUrl: String { | |
return "https://www.example.com" | |
} | |
var path: String? { | |
switch self { | |
case .one: return "/path/one" | |
case .two: return "/path/two" | |
case .three: return "/path/three" | |
} | |
} | |
var httpMethod: String { | |
switch self { | |
case .one: return "GET" | |
case .two: return "POST" | |
case .three: return "DELETE" | |
} | |
} | |
var httpBody: Data? { | |
switch self { | |
case .one: return Data() | |
case .two: return nil | |
case .three: return nil | |
} | |
} | |
var allHTTPHeaderFields: [String : String] { | |
var headers: [String: String] = ["CommonKey": "CommonValue"] | |
switch self { | |
case .one: headers["OnlyForEndpointOneKey"] = "OnlyForEndpointOneValue" | |
case .two: headers["OnlyForEndpointTwoKey"] = "OnlyForEndpointTwoValue" | |
case .three: headers["OnlyForEndpointThreeKey"] = "OnlyForEndpointThreeValue" | |
} | |
return headers | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment