An open API service indexing awesome lists of open source software.

https://github.com/paul-caron/curling

A C++ libcurl wrapper
https://github.com/paul-caron/curling

cpp17 curl easy header-only http-client libcurl mit-license modern-cpp rest-api shared-library

Last synced: 2 months ago
JSON representation

A C++ libcurl wrapper

Awesome Lists containing this project

README

          

![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-passing-brightgreen)
[![Build and Test](https://github.com/paul-caron/curling/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/paul-caron/curling/actions/workflows/build-and-test.yml)
![C++17](https://img.shields.io/badge/C%2B%2B-17-blue)
![GitHub release](https://img.shields.io/github/v/release/paul-caron/curling?include_prereleases&sort=semver)

# ๐ŸŒ€ Curling

Curling is a modern C++17 wrapper around libcurl, designed to simplify HTTP/HTTPS requests using a clean, fluent API.

It supports JSON payloads, file uploads, cookie management, authentication, proxy configuration, and more โ€” all with a RAII-safe design using smart pointers.

---

## ๐Ÿ“š Table of Contents

- [โœจ Features](#-features)
- [๐Ÿ›  Installation](#-installation)
- [๐Ÿš€ Basic Usage](#-basic-usage)
- [โœ… Example Test Case](#-example-test-case)
- [๐Ÿง  Internals & Design](#-internals--design)
- [๐Ÿค” Why Curling?](#-why-curling)
- [โš–๏ธ Comparisons](#๏ธ-comparisons-with-other-popular-c-libcurl-wrappers)
- [๐Ÿ“š Documentation](#-documentation)
- [๐Ÿงช Testing](#-testing)
- [๐Ÿค Contributing](#-contributing)
- [๐Ÿ“„ License](#-license)
- [๐Ÿ‘ค Maintainer](#-maintainer)
- [๐Ÿ“Œ Notes](#-notes)

---

## โœจ Features

- ๐Ÿ” **Fluent API** โ€” chainable and expressive request building
- ๐Ÿ“ค **Multipart and MIME support** โ€” for multipart forms and file uploads
- ๐Ÿช **Cookie management** โ€” with optional persistent storage
- ๐Ÿ›ก **Proxy and authentication support** โ€” including Basic, Bearer, and Digest
- ๐ŸŒ **Full HTTP verb support** โ€” GET, POST, PUT, DELETE, PATCH, HEAD
- ๐Ÿš€ **HTTP/2 and HTTP/3 support** โ€” via libcurl
- โณ **Progress callback support** โ€” for monitoring request progress
- ๐Ÿงฉ **Header-only library** โ€” just include and go
- ๐Ÿ“ฆ **.deb packaging** โ€” for easy installation on Debian-based systems
- ๐Ÿงช **CI-tested** โ€” with [Doctest](https://github.com/doctest/doctest) and GitHub Actions

---

## ๐Ÿ›  Installation

### ๐Ÿ”ง Build shared library

```bash
make
```

To install and package as a Debian .deb:

```bash
make install
make deb
```

Install it locally:

```bash
sudo apt install ./curling_1.0_amd64.deb
sudo ldconfig
```

### ๐Ÿชถ Header-only version

```bash
make header-only
```

This produces a header-only version in:

`curling/header-only/`

---

## ๐Ÿš€ Basic Usage

```cpp
#include "curling.hpp"
#include

int main() {
curling::Request req;

auto res = req.setMethod(curling::Request::Method::GET)
.setURL("https://example.com")
.setUserAgent("Lizardzilla/6.9 (Reptilian Humanoid)")
.send();

std::cout << res.toString();
return 0;
}
```

### ๐Ÿ”จ Compile

With shared library:
```bash
g++ main.cpp -lcurling -std=c++17
```
With header-only:
```bash
g++ main.cpp -lcurl -std=c++17
```

---

## โœ… Example Test Case

Tests run automatically on every push via GitHub Actions.

```cpp
TEST_CASE("GET request to download image") {
curling::Request req;
req.setURL("https://httpbin.org/image/png")
.downloadToFile("out.png");

auto res = req.send();

CHECK(res.httpCode == 200);
CHECK(std::filesystem::exists("out.png"));
}
```

Run tests locally:
```bash
make test
```

---

## ๐Ÿง  Design Philosophy

Curling centers around the curling::Request class, which wraps libcurl functionality in a fluent, type-safe, modern C++ API.

Key principles:

- โœ… RAII & smart pointers โ€” automatic resource cleanup

- โœ… Fluent chaining โ€” readable and efficient method calls

- โœ… No global state โ€” avoids curl_global_* leaks

- โœ… Safe-by-default โ€” redirects off by default, verbose off, etc.

---

## ๐Ÿค” Why Curling?

Libcurl is powerful, but its C API is verbose and error-prone.

Curling offers:

|Feature |libcurl |Curling|
|------------------------|-----------|-------|
|Fluent C++ API |โŒ |โœ… |
|RAII memory management |โŒ |โœ… |
|Built-in test coverage |โŒ |โœ… |
|Easy file & MIME upload |Manual |โœ… |
|Modern build integration|โŒ |โœ… |

---

## โš–๏ธ Comparisons with Other Popular C++ libcurl Wrappers

Curling aims to strike a balance between modern C++ design, fine-grained control, and ease of use. Here's how it compares to other popular libcurl wrappers:

| Aspect | CPR | curlpp | Curling (this project) |
|---------------------|-------------------------------|-----------------------------|--------------------------------------------|
| API Style | High-level, intuitive | Classic wrapper, less modern| Modern C++17 fluent API with chaining |
| Abstraction Level | Heavy abstraction, hides internals | Moderate abstraction, outdated | Balanced abstraction, exposes fine control|
| Memory Management | Manual (raw pointers internally) | Manual | RAII with smart pointers |
| Feature Completeness| Common HTTP (GET/POST/JSON/auth)| Full libcurl coverage, less ergonomic | Full HTTP verbs, MIME, advanced auth |
| File/MIME Upload | Partial support, verbose | Supported, clunky | Fully integrated, fluent MIME support |
| Authentication | Basic, Bearer | Basic, Digest | Basic, Bearer, Digest (incl. SHA-256) |
| Build & Packaging | Shared/static via CMake | Static/shared library | Header-only mode + Debian `.deb` packaging |
| Test Coverage | Minimal | Minimal | Full coverage with Doctest + CI |
| Thread Safety | Not guaranteed | Not guaranteed | Not thread-safe (documented) |
| Customization | Limited | Moderate | Extensive fine-tuned libcurl control |
| Docs & Examples | Good docs, simple examples | Sparse | Rich examples + auto-generated Doxygen docs|
| Community | Active, popular | Aging, low activity | Growing with CI, automation, and tests |

### Why Choose Curling Over CPR or curlpp?

More control, less complexity: Full access to advanced libcurl options via a modern interface.

RAII-safe: Automatic cleanup prevents memory and resource leaks.

Rich MIME and auth support: Complex uploads and multiple authentication schemes are built-in.

Flexible builds: Choose between header-only use or .deb packages for installation.

CI and tests: Every commit is tested, ensuring high reliability.

Safe defaults: Redirects and verbose logging are disabled by default, encouraging secure usage.

---

## ๐Ÿ“š Documentation

Generate API documentation with Doxygen:

```bash
make doc
```

HTML output will appear in the doc/ folder.

To clean:

```bash
make doc-clean
```

---

## ๐Ÿงช Testing

Tests use Doctest and cover:

- โœ… HTTP verbs: GET, POST, PUT, PATCH, DELETE, MIME

- โœ… Authentication: Basic, Bearer, Digest (MD5, SHA-256, auth-int)

- โœ… File download and upload

- โœ… Header manipulation

- โœ… JSON and form-data handling

- โœ… Redirect handling

Run locally:

```bash
make test
```

GitHub Actions ensures tests pass on every push and pull request.

---

## ๐Ÿค Contributing

Contributions are welcome! Please:

Format code consistently

Run make test before pushing

Use atomic and focused commits

---

## ๐Ÿ“„ License

This project is licensed under the MIT License.

---

## ๐Ÿ‘ค Maintainer

Paul Caron

---

## ๐Ÿ“Œ Notes

Curl global init/cleanup is handled automatically.

Not thread-safe โ€” avoid sharing curling::Request across threads.

MIME is a distinct HTTP method type (not used with POST/PUT).

---