CURL
public struct CURL : Sendable
CURL converts a line of curl command into a URLRequest object. It helps
you to create HTTP clients for your iOS/macOS/tvOS apps easier once you have
a example curl command.
For example. if you want to fetch a file in JSON format from httpbin.org, you can use only one line of Swift code:
try URL("https://httpbin.org/json").run { data, response, error in ... }
-
Creates a new instance.
Please note that the method throws errors if the syntax is invalid in your curl command.
Declaration
Swift
public init(_ str: String) throwsParameters
strThe command in string format.
-
Builds a
URLRequestobject from the given command.Declaration
Swift
public func buildRequest() -> URLRequest -
Runs the fetch command with a callback closure.
Declaration
Swift
public func run(completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> ())Parameters
completionHandlerThe callback closure.