Request
public struct Request<Output>
A HTTP request safely typed for an Output
response
Highly inspired by https://swiftwithmajid.com/2021/02/10/building-type-safe-networking-in-swift/
-
request relative path
Declaration
Swift
public let path: Path
-
Declaration
Swift
public let method: Method
-
Declaration
Swift
public let body: Body?
-
Declaration
Swift
public let query: [String : QueryParam]
-
Declaration
Swift
public var cachePolicy: URLRequest.CachePolicy
-
Declaration
Swift
public var headers: HTTPHeaderFields
-
Creates a request suitable for a HTTP GET
Declaration
Swift
public static func get(_ path: Path, query: [String : QueryParam] = [:]) -> Request<Output>
-
Creates a request suitable for a HTTP POST with a
Encodable
bodyDeclaration
Swift
public static func post(_ path: Path, body: Encodable?, query: [String: QueryParam] = [:]) -> Self
-
Creates a request suitable for a HTTP POST with a
MultipartFormData
bodyDeclaration
Swift
@_disfavoredOverload public static func post(_ path: Path, body: MultipartFormData?, query: [String: QueryParam] = [:]) -> Self
-
Creates a request suitable for a HTTP PUT with a
Encodable
bodyDeclaration
Swift
public static func put(_ path: Path, body: Encodable, query: [String: QueryParam] = [:]) -> Self
-
Creates a request suitable for a HTTP PUT with a
MultipartFormData
bodyDeclaration
Swift
public static func put(_ path: Path, body: MultipartFormData, query: [String: QueryParam] = [:]) -> Self
-
Create a HTTP PUT request with no body
Declaration
Swift
public static func put(_ path: Path, query: [String : QueryParam] = [:]) -> Request<Output>
-
Creates a request suitable for a HTTP PATCH with a
Encodable
bodyDeclaration
Swift
public static func patch(_ path: Path, body: Encodable, query: [String: QueryParam] = [:]) -> Self
-
Creates a request suitable for a HTTP PATCH with a
MultipartFormData
bodyDeclaration
Swift
public static func patch(_ path: Path, body: MultipartFormData, query: [String: QueryParam] = [:]) -> Self
-
Creates a request suitable for a HTTP DELETE
Declaration
Swift
public static func delete(_ path: Path, query: [String : QueryParam] = [:]) -> Request<Output>
-
Creates a DELETE request with a Encodable body
Declaration
Swift
public static func delete(_ path: Path, body: Encodable, query: [String : QueryParam] = [:]) -> Request<Output>
-
Creates a Request.
Use this init only if default provided static initializers (
.get
,.post
,.put
,patch
,.delete
) do not suit your needs.Declaration
Swift
public init(path: Path, method: Method, query: [String : QueryParam], body: Body?)
-
Adds headers to the request
Declaration
Swift
public func headers(_ newHeaders: [HTTPHeader : String]) -> Request<Output>
-
Configures request cache policy
Declaration
Swift
public func cachePolicy(_ policy: URLRequest.CachePolicy) -> Request<Output>
-
Transform a Request into a URLRequest
Declaration
Swift
public func toURLRequest( encoder: ContentDataEncoder, relativeTo baseURL: URL, accepting: ContentDataDecoder? = nil ) throws -> URLRequest
Parameters
encoder
the encoder to use to encode the body is present
relativeTo
the base URL to append to the request path
accepting
if not nil will be used to set “Accept” header value