Curlite is developed as a lightweight wrapper over cURL library with the following points in mind:
- Support of C++11 features
- Type safety of curl options
- Ease-of-use
- No external dependencies (except libcurl)
The project is in development stage. Currently only Easy
interface is implemented.
try
{
curlite::Easy easy;
easy.set( CURLOPT_URL, "http://example.com" );
easy.set( CURLOPT_FOLLOWLOCATION, true );
// start download
std::cout << easy;
}
catch( std::exception &e ) {
std::cerr << "Got an exception: " << e.what() << std::endl;
}
or just use curlite::download()
method:
try
{
curlite::download( "http://example.com", std::cout, true );
}
catch( std::exception &e ) {
std::cerr << "Got an exception: " << e.what() << std::endl;
}
try
{
curlite::Easy easy;
easy.set( CURLOPT_URL, "ftp://example.com/file.txt" );
easy.set( CURLOPT_USERNAME, "username" );
easy.set( CURLOPT_PASSWORD, "password" );
easy.set( CURLOPT_UPLOAD, true );
// open input file stream
std::ifstream ifs( "file.txt", std::ios::binary );
// start upload
ifs >> easy;
double totalSecs = easy.getInfo<double>( CURLINFO_TOTAL_TIME );
std::cout << "Upload time: " << totalSecs << " s" << std::endl;
}
catch( std::exception &e ) {
std::cerr << "Got an exception: " << e.what() << std::endl;
return 1;
}
And the same with curlite::upload()
method:
try
{
std::ifstream ifs( "file.txt", std::ios::binary );
auto easy = curlite::upload( ifs, "ftp://example.com/file.txt", "username", "password" );
double totalSecs = easy.getInfo<double>( CURLINFO_TOTAL_TIME );
std::cout << "Upload time: " << totalSecs << " s" << std::endl;
}
catch( std::exception &e ) {
std::cerr << "Got an exception: " << e.what() << std::endl;
}
Curlite should work with libcurl 7.32 and later.
Curlite requires from compiler a basic support of C++11. The minimum supported version are: g++ 4.6, clang 3.2, VS 2010 and later.
The latter (with underscore) sets simplified handler, while the first sets usual cURL handler.
No, they are not.
I like those libraries, but in some cases libcurl is the best choice: it's easy, stable and supports a huge number of protocols. Download via HTTPS? - ok. Send email? - no problem.