Skip to content

Instantly share code, notes, and snippets.

@Juanpe
Last active March 26, 2019 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Juanpe/8c902c8c0c5f342767a67ee62308d5e2 to your computer and use it in GitHub Desktop.
Save Juanpe/8c902c8c0c5f342767a67ee62308d5e2 to your computer and use it in GitHub Desktop.
//This defines the type of HTTP method used to perform the request
enum HTTPMethod: String {
case post = "POST"
case put = "PUT"
case get = "GET"
case delete = "DELETE"
case patch = "PATCH"
}
//This defines the parameters to pass along with the request
enum RequestParams {
case body(_: [String: Any]?)
case url(_: [String: Any]?)
}
//This is the `APIRequest` protocol you may implement other classes can conform
protocol APIRequest {
associatedtype Resource: Decodable
var baseURL: URL { get }
var path: String { get }
var method: HTTPMethod { get }
var parameters: RequestParams { get }
var headers: [String: Any]? { get }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment