Skip to content

A modern C++20 HTTP/HTTPS client library based on ASIO with coroutine-based async/await support

License

Notifications You must be signed in to change notification settings

harvestsure/coro-http

Repository files navigation

coro_http

windows ubuntu macos

A modern C++20 HTTP/HTTPS client library with coroutine-based async/await API.

Features

  • ✅ HTTP/HTTPS support with SSL/TLS
  • ✅ C++20 coroutines for async operations
  • ✅ Connection pooling with Keep-Alive
  • ✅ Automatic redirects and compression
  • ✅ Retry policies with exponential backoff
  • ✅ Rate limiting and timeout control
  • ✅ Proxy support (HTTP/HTTPS/SOCKS5)
  • ✅ Server-Sent Events (SSE) streaming
  • ✅ Header-only library

Quick Start

Coroutine API

#include <coro_http/coro_http.hpp>

int main() {
    asio::io_context io_ctx;
    coro_http::CoroHttpClient client(io_ctx);
    
    client.run([&]() -> asio::awaitable<void> {
        auto response = co_await client.co_get("https://api.github.com/users/github");
        std::cout << "Status: " << response.status_code() << "\n";
    });
    
    return 0;
}

Server-Sent Events (SSE)

coro_http::HttpRequest request(coro_http::HttpMethod::GET, "https://example.com/events");
request.add_header("Accept", "text/event-stream");

co_await client.co_stream_events(request, [](const coro_http::SseEvent& event) {
    std::cout << "Event type: " << event.type << "\n";
    std::cout << "Data: " << event.data << "\n";
});

Requirements

  • C++20 compiler
  • CMake 3.20+
  • OpenSSL, zlib

Installation

git clone https://github.com/harvestsure/coro-http.git
cd coro-http
mkdir build && cd build
cmake ..
make

Documentation

For detailed documentation, see:

License

MIT License

About

A modern C++20 HTTP/HTTPS client library based on ASIO with coroutine-based async/await support

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published