Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 24, 2026·2 min de lectura

C++ Requests (cpr) — Curl for People

cpr is a modern C++ HTTP client library inspired by Python Requests. It wraps libcurl in a clean, intuitive API that makes HTTP calls as simple as writing Python.

Listo para agents

Instalación con revisión previa

Este activo requiere revisión. El prompt copiado pide dry-run, muestra escrituras y continúa solo tras confirmación.

Needs Confirmation · 64/100Política: confirmar
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
cpr
Comando con revisión previa
npx -y tokrepo@latest install 0b595c6c-87a2-11f1-9bc6-00163e2b0d79 --target codex

Primero dry-run, confirma las escrituras y luego ejecuta este comando.

Introduction

cpr brings the simplicity of Python's Requests library to C++. Instead of wrestling with libcurl's C API, developers write clean, expressive HTTP calls using familiar patterns like cpr::Get, cpr::Post, and named parameters.

What cpr Does

  • Performs HTTP GET, POST, PUT, DELETE, PATCH, and HEAD requests with a fluent API
  • Handles authentication, cookies, redirects, and SSL verification automatically
  • Supports asynchronous requests via std::future for non-blocking I/O
  • Manages multipart file uploads and form-encoded data
  • Provides session objects for connection reuse and persistent settings

Architecture Overview

cpr is a C++ wrapper around libcurl. Each request function constructs a curl handle, applies named parameters (URL, headers, body, auth), executes the transfer, and returns a Response object with status, headers, and body. Sessions maintain a curl handle across requests for connection pooling.

Self-Hosting & Configuration

  • Install via vcpkg, Conan, or CMake FetchContent with automatic libcurl bundling
  • Link with cpr::cpr in CMake; libcurl is fetched and built automatically if not found
  • Set timeouts with cpr::Timeout{milliseconds} parameter
  • Configure SSL certificates with cpr::SslOptions
  • Use cpr::Session for persistent headers, cookies, and base URLs

Key Features

  • Python-Requests-style API that feels natural to C++ developers
  • Automatic libcurl bundling eliminates manual dependency management
  • Async request support via cpr::GetAsync returning std::future
  • Built-in support for HTTP/2 and connection multiplexing via libcurl
  • Thread-safe session objects for concurrent request patterns

Comparison with Similar Tools

  • libcurl (C) — libcurl is the underlying engine; cpr adds a modern C++ API layer that reduces boilerplate significantly
  • cpp-httplib — cpp-httplib is header-only with its own HTTP stack; cpr leverages libcurl's mature networking layer
  • Boost.Beast — Beast provides low-level HTTP on Boost.Asio; cpr is higher-level and simpler for typical REST calls
  • httplib — httplib suits simple use cases; cpr handles advanced scenarios like HTTP/2, proxies, and async natively

FAQ

Q: Does cpr bundle libcurl? A: Yes. If libcurl is not found on the system, CMake fetches and builds it automatically.

Q: Is cpr thread-safe? A: Individual requests are thread-safe. Session objects should not be shared across threads without synchronization.

Q: Does cpr support HTTP/2? A: Yes, when the underlying libcurl is built with HTTP/2 support (nghttp2).

Q: What C++ standard does cpr require? A: cpr requires C++17 or later.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados