Skip to content

A Swift wrapper around libcurl that works with Linux

License

Notifications You must be signed in to change notification settings

in2core/CCurl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CCurl

A Swift wrapper around libcurl that works with Linux. Because curl_easy_setopt is a variadic function and so is not imported by Swift, additional wrapper functions are provided to get around the problem, such as:

  • curl_easy_setopt_string
  • curl_easy_setopt_bool

Dependencies

For Linux you need:

sudo apt-get install libcurl4-openssl-dev

Usage

This component is set up to be used with the Swift Package Manager.

Add this line to your dependencies section:

.package(url: "https://github.com/in2core/CCurl.git", .branch("master"))

Example Application

In a new directory, create Package.swift:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "CCurlTest",
    products: [
        .executable(name: "CCurlTest", targets: ["CCurlTest"])
    ],
    dependencies: [
        .package(url: "https://github.com/in2core/CCurl.git", .branch("master"))
    ],
    targets: [
        .target(name: "CCurlTest", dependencies: ["CCurl"], path: ".")
    ]
)

Now create main.swift:

import CCurl

let handle = curl_easy_init()

curl_easy_setopt_string(handle, CURLOPT_URL, "http://www.example.com")
curl_easy_setopt_bool(handle, CURLOPT_VERBOSE, true)

let ret = curl_easy_perform(handle)
if let error = curl_easy_strerror(ret) {
    print("error = \(error)")
}
print("ret = \(ret)")

Build the app: swift build

Run the app: .build/debug/CCurlTest

About

A Swift wrapper around libcurl that works with Linux

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 83.7%
  • Swift 16.3%