CURL
public struct CURL : Sendable
CURL converts a cURL command string into a URLRequest object. This makes
it easier to build HTTP clients for iOS, macOS, or tvOS applications using
example cURL commands.
For example, if you want to fetch a JSON file from httpbin.org, you can do so with a single line of Swift code:
try CURL("https://httpbin.org/json").run { data, response, error in ... }
-
Initializes a new instance.
Note that this initializer throws an error if the provided cURL command has invalid syntax.
Declaration
Swift
public init(_ str: String) throwsParameters
strThe cURL command as a string.
-
Constructs a
URLRequestobject from the parsed cURL command.Declaration
Swift
public func buildRequest() -> URLRequest -
Executes the fetch command and returns the result via a callback closure.
Declaration
Swift
public func run(completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> ())Parameters
completionHandlerThe closure to call upon completion.