GithubHelp home page GithubHelp logo

hhy5277 / cpr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from libcpr/cpr

0.0 1.0 0.0 481 KB

C++ Requests: Curl for People, a spiritual port of Python Requests

Home Page: http://whoshuu.github.io/cpr/

License: MIT License

CMake 4.15% C++ 95.52% Shell 0.26% C 0.06%

cpr's Introduction

C++ Requests: Curl for People

Build Status 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/cpr.h>

int main(int argc, char** argv) {
    auto r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
                      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.

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
  • Timeout for low speed connection
  • Asynchronous requests
  • ๐Ÿช support!
  • Proxy support
  • Callback interface
  • PUT methods
  • DELETE methods
  • HEAD methods
  • OPTIONS methods
  • PATCH methods

Planned

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

and much more!

Usage

For just getting this library up and running, I highly recommend forking the example project. It's configured with the minimum CMake magic and boilerplate needed to start playing around with networked applications.

If you already have a project you need to integrate C++ Requests with, the primary way is to use git submodules. Add this repository as a submodule of your root repository:

git submodule add [email protected]:whoshuu/cpr.git
OR 
git submodule add https://github.com/whoshuu/cpr.git

git submodule update --init --recursive

Next, add this subdirectory to your CMakeLists.txt before declaring any targets that might use it:

add_subdirectory(cpr)

This will produce two important CMake variables, CPR_INCLUDE_DIRS and CPR_LIBRARIES, which you'll use in the typical way:

include_directories(${CPR_INCLUDE_DIRS})
target_link_libraries(your_target_name ${CPR_LIBRARIES})

and that should do it! Using the submodule method of integrating C++ Requests, there's no need to handle libcurl yourself, all of those dependencies are taken care of for you.

Requirements

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
  • curl and its development libraries

cpr's People

Contributors

adam-nielsen avatar aldanor avatar andreasgerstmayr avatar antonlindstrom avatar apollo13 avatar bandzaw avatar bobjansen avatar cylix avatar danyspin97 avatar erengy avatar felixvanorder avatar guoxiao avatar hdak1945git avatar himanshub16 avatar keyvec avatar klaussilveira avatar mexus avatar nabijaczleweli avatar noh4hss avatar pravic avatar sam-bristow avatar skystrife avatar smiley avatar thedrow avatar vittorioromeo avatar whoshuu avatar xpol avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.