Skip to content

Instantly share code, notes, and snippets.

@SwiftyAlex
Last active September 23, 2019 07:10
Show Gist options
  • Save SwiftyAlex/555c786f25206989ec1a2f728aa34cf3 to your computer and use it in GitHub Desktop.
Save SwiftyAlex/555c786f25206989ec1a2f728aa34cf3 to your computer and use it in GitHub Desktop.
Route Protocol
public protocol Route {
/// Request & ResponseType are forced, but `Empty` allows you to skip encoding/decoding
associatedtype RequestType: Encodable
associatedtype ResponseType: Decodable
static var method: HTTPMethod { get }
static var path: String { get }
static var requiresAuth: Bool { get }
/// Optional instance of `RequestType` that gets encoded if present
var requestObject: RequestType? { get set }
/// Any query parameters.
var queryParemeters: [URLQueryItem] { get set }
/// Any path items that we can then encode to the request string. These will be appended in the order they are found within the array
var pathParameters: [String] { get }
/// This function has a generic implenetation for the more simple routes, all others should have their own.
func toRequest() -> URLRequest
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment