HTTPRequest
HTTPRequest.swift:11struct HTTPRequest
struct HTTPRequest
import Utils
init(request: URLRequest, session: URLSession? = nil)
init(scheme: String = "https", host: String, port: Int? = nil, path: String, method: String = "GET", query: [String : String] = [:], headers: [String : String] = [:], body customBody: String? = nil, session: URLSession = URLSession.shared) throws
init(url: URL, session: URLSession? = nil)
func fetchHTML() async throws -> Document
Runs the request and asynchronously parses the response as HTML.
func fetchHTMLAsync() -> Promise<Document, Error>
Runs the request and returns a Promise
with the parsed HTML document.
func fetchJSON<T>(as type: T.Type) async throws -> T where T : Decodable, T : Sendable
Runs the request and asynchronously decodes the response as JSON.
func fetchJSONAsync<T>(as type: T.Type) -> Promise<T, Error> where T : Decodable, T : Sendable
Runs the request and returns a Promise
with the value decoded from the response interpreted as JSON.
func fetchUTF8() async throws -> String
Runs the request and asynchronously returns the UTF-8-decoded response.
func fetchUTF8Async() -> Promise<String, Error>
Runs the request and returns a Promise
with the UTF-8-decoded response.
func fetchXML<T>(as type: T.Type) async throws -> T where T : Decodable, T : Sendable
Runs the request and asynchronously decodes the response as XML.
func fetchXMLAsync<T>(as type: T.Type) -> Promise<T, Error> where T : Decodable, T : Sendable
Runs the request and returns a Promise
with the value decoded from the response interpreted as XML.
func fetchXMLAsync(using delegateFactory: @escaping () -> any XMLParserDelegate)
Runs the request and interprets the response as XML via the given delegate.
func fetchXMLAsync(using delegate: any XMLParserDelegate & Sendable)
Runs the request and interprets the response as XML via the given delegate.
@discardableResult func run() async throws -> Data
Runs the request and asynchronously returns the response.
func runAsync() -> Promise<Data, Error>
Runs the request and returns a Promise
with the response.