Skip to content
Branch: master
Go to file

Latest commit

dilshodm committed 65d0bf1 Jul 4, 2020
Fix for Parameters using string variable (#413)
* Broken API: can't use Parameters{{my_string_key, my_string_value}}

The Parameter constructor accepts only r-value references which forces to use string variables as:
Parameters{{my_string_key.c_str(), my_string_value.c_str()}}.
Added const reference to strings constructor

* Test for Parameters added


Failed to load latest commit information.

C++ Requests: Curl for People

gitter Documentation CI Coverage Status


The cpr project will have a new maintainer: Fabian Sauter and Tim Stack. He has graciously agreed to donate his time to keep the project healthy and grow it. For those waiting on their PRs and issues to be resolved, I appreciate your patience and know that you will be in good hands moving forward.


C++ Requests is a simple wrapper around libcurl inspired by the excellent Python Requests project.

Despite its name, libcurl's easy interface is anything but, and making mistakes misusing it is a common source of error and frustration. Using the more expressive language facilities of C++11, this library captures the essence of making network calls into a few concise idioms.

Here's a quick GET request:

#include <cpr/cpr.h>

int main(int argc, char** argv) {
    auto r = cpr::Get(cpr::Url{""},
                      cpr::Authentication{"user", "pass"},
                      cpr::Parameters{{"anon", "true"}, {"key", "value"}});
    r.status_code;                  // 200
    r.header["content-type"];       // application/json; charset=utf-8
    r.text;                         // JSON text string

And here's less functional, more complicated code, without cpr.


You can find the latest documentation here. It's a work in progress, but it should give you a better idea of how to use the library than the tests currently do.


C++ Requests currently supports:

  • Custom headers
  • Url encoded parameters
  • Url encoded POST values
  • Multipart form POST upload
  • File POST upload
  • Basic authentication
  • Digest authentication
  • NTLM authentication
  • Connection and request timeout specification
  • Timeout for low speed connection
  • Asynchronous requests
  • 🍪 support!
  • Proxy support
  • Callback interface
  • PUT methods
  • DELETE methods
  • HEAD methods
  • OPTIONS methods
  • PATCH methods


Support for the following will be forthcoming (in rough order of implementation priority):

and much more!


If you already have a project you need to integrate C++ Requests with, the primary way is to use CMake fetch_content. Add the following to your CMakeLists.txt.

FetchContent_Declare(cpr GIT_REPOSITORY

This will produce the target cpr::cpr which you can link against the typical way:

target_link_libraries(your_target_name PRIVATE cpr::cpr)

That should do it! There's no need to handle libcurl yourself. All dependencies are taken care of for you.


The only explicit requirements are:

  • a C++11 compatible compiler such as Clang or GCC. The minimum required version of GCC is unknown, so if anyone has trouble building this library with a specific version of GCC, do let me know
  • If you would like to perform https requests OpenSSL and its development libraries are required.

Building cpr - Using vcpkg

You can download and install cpr using the vcpkg dependency manager:

git clone
cd vcpkg
./vcpkg integrate install
./vcpkg install cpr

The cpr port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

You can’t perform that action at this time.