Vernissage/PixelfedKit/Sources/PixelfedKit/Networking/TargetType.swift

32 lines
801 B
Swift
Raw Normal View History

2023-01-20 16:57:25 +01:00
//
// https://mczachurski.dev
// Copyright © 2022 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-01-20 16:57:25 +01:00
//
2023-01-10 08:04:25 +01:00
import Foundation
public enum NetworkingError: String, Swift.Error {
case cannotCreateUrlRequest
}
public enum Method: String {
case delete = "DELETE", get = "GET", head = "HEAD", patch = "PATCH", post = "POST", put = "PUT"
}
public protocol TargetType {
var path: String { get }
var method: Method { get }
var headers: [String: String]? { get }
var queryItems: [(String, String)]? { get }
var httpBody: Data? { get }
}
extension [String: String] {
var contentTypeApplicationJson: [String: String] {
var selfCopy = self
selfCopy["content-type"] = "application/json"
return selfCopy
}
}