restclient.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @file restclient.h
  3. * @brief libcurl wrapper for REST calls
  4. * @author Daniel Schauenberg <d@unwiredcouch.com>
  5. * @version
  6. * @date 2010-10-11
  7. */
  8. #ifndef INCLUDE_RESTCLIENT_CPP_RESTCLIENT_H_
  9. #define INCLUDE_RESTCLIENT_CPP_RESTCLIENT_H_
  10. #include <string>
  11. #include <map>
  12. #include <cstdlib>
  13. /**
  14. * @brief namespace for all RestClient definitions
  15. */
  16. namespace RestClient {
  17. /**
  18. * public data definitions
  19. */
  20. typedef std::map<std::string, std::string> HeaderFields;
  21. /** @struct Response
  22. * @brief This structure represents the HTTP response data
  23. * @var Response::code
  24. * Member 'code' contains the HTTP response code
  25. * @var Response::body
  26. * Member 'body' contains the HTTP response body
  27. * @var Response::headers
  28. * Member 'headers' contains the HTTP response headers
  29. */
  30. typedef struct {
  31. int code;
  32. std::string body;
  33. HeaderFields headers;
  34. } Response;
  35. // init and disable functions
  36. int init();
  37. void disable();
  38. /**
  39. * public methods for the simple API. These don't allow a lot of
  40. * configuration but are meant for simple HTTP calls.
  41. *
  42. */
  43. Response get(const std::string& url);
  44. Response post(const std::string& url,
  45. const std::string& content_type,
  46. const std::string& data);
  47. Response put(const std::string& url,
  48. const std::string& content_type,
  49. const std::string& data);
  50. Response del(const std::string& url);
  51. Response head(const std::string& url);
  52. Response download(const std::string& url, std::string path_to_save);
  53. } // namespace RestClient
  54. #endif // INCLUDE_RESTCLIENT_CPP_RESTCLIENT_H_