cpr
C++ Requests: Curl for People, a spiritual port of Python Requests.
A C++ library that makes HTTP requests simple, GET, POST, file uploads, with a clean one-line function call instead of the dozens of lines of setup code that libcurl normally requires.
CPR (C++ Requests) is a C++ library for making HTTP requests, the kind of network call an application makes when it needs to talk to a web server or external API. The library wraps an older, lower-level tool called libcurl, which works reliably but requires a lot of boilerplate code to use directly. CPR hides that complexity behind a simpler interface, modeled after Python's popular Requests library.
In practice this means that fetching data from a web address, sending form data, or uploading a file goes from dozens of lines of configuration code down to a single readable function call. The library supports all common request types: GET (fetch data), POST (submit data), PUT (update), DELETE, and others used in web APIs. It also handles authentication (Basic, Bearer, Digest, and NTLM), cookies, proxy servers, connection timeouts, and HTTPS encryption.
Requests can be made synchronously, where your program waits for the response before continuing, or asynchronously, where the request runs in the background and a callback is triggered when the response arrives. The library is built to work safely when multiple parts of a program are making requests at the same time, which is a requirement in multi-threaded applications.
Installation is available through several routes. C++ projects using CMake can pull CPR in automatically as a dependency without managing libcurl separately. Package managers exist for Arch Linux, Fedora, Windows (NuGet), macOS (MacPorts), and FreeBSD. A C++17-compatible compiler is required for current versions, though older releases supported C++11.
Where it fits
- Fetch JSON data from a REST API in a C++ application with a single readable GET call instead of libcurl boilerplate
- Send POST requests with form fields or file uploads to a web server from a C++ program
- Make asynchronous HTTP requests in a multi-threaded C++ application so the rest of the program keeps running while waiting for a response