Skip to content

Instantly share code, notes, and snippets.

@adamzarn
Last active February 28, 2022 19:44
Show Gist options
  • Save adamzarn/f5049d5b775ebdf077b22556f09f4a4a to your computer and use it in GitHub Desktop.
Save adamzarn/f5049d5b775ebdf077b22556f09f4a4a to your computer and use it in GitHub Desktop.
A template for an Endpoint enum that implements URLRequestConvertible
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