Skip to content
/ cpr Public
forked from libcpr/cpr

C++ Requests: Curl for People, a spiritual port of Python Requests (https://github.com/kennethreitz/requests)

License

Notifications You must be signed in to change notification settings

lucasshrew/cpr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Requests: Curl for People

Build Status Coverage Status Documentation

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.h>

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

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

Documentation

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.

Features

C++ Requests currently supports:

  • Custom headers
  • Url encoded parameters
  • Url encoded POST values
  • Multipart form POST upload
  • File POST upload
  • Basic authentication
  • Digest authentication
  • Timeout specification
  • Asynchronous requests
  • 🍪 support!
  • Proxy support

Planned

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

and much more!

Install

The easiest way to install is to use cmake:

mkdir build
cd build
cmake ..
make

By default, the embedded libcurl is used by this library. If you want to use your system libcurl, then run:

cmake -DUSE_SYSTEM_CURL=ON ..
make

A successful build should produce a single library archive that you can link against your project. You should also make the include directory visible to your build as well so that you can include cpr.h.

Requirements

The only explicit requirement is 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.

Disclaimer

This library is very much in a pre-alpha stage. Please don't attempt to use this in any serious or critical production environment. If you do use it and find bugs you'd like to report, see below!

Contributing

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.

About

C++ Requests: Curl for People, a spiritual port of Python Requests (https://github.com/kennethreitz/requests)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 94.5%
  • CMake 5.2%
  • C 0.3%