CURL

public struct CURL

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

    Parameters

    str

    The command in string format.

  • Builds a URLRequest object 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 (Data?, URLResponse?, Error?) -> ())

    Parameters

    completionHandler

    The callback closure.

  • Runs the fetch command and handles the reponse with a handler object.

    The handler should be a subclass of Handler.

    Declaration

    Swift

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

    Parameters

    handler

    The handler.