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) throws

    Parameters

    str

    The cURL command as a string.

  • Constructs a URLRequest object 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

    completionHandler

    The closure to call upon completion.

  • Executes the fetch command and processes the response using a handler object.

    The handler must be a subclass of Handler.

    Declaration

    Swift

    public func run<T>(handler: Handler<T>)

    Parameters

    handler

    The handler.