You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
782B

  1. #pragma once
  2. #include <common.hpp>
  3. #include <jansson.h>
  4. namespace rack {
  5. /** Networking functions for HTTP requests, URLs, and downloads
  6. */
  7. namespace network {
  8. enum Method {
  9. METHOD_GET,
  10. METHOD_POST,
  11. METHOD_PUT,
  12. METHOD_DELETE,
  13. };
  14. void init();
  15. /** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc)
  16. Caller must json_decref().
  17. */
  18. json_t* requestJson(Method method, std::string url, json_t* dataJ);
  19. /** Returns true if downloaded successfully */
  20. bool requestDownload(std::string url, const std::string& filename, float* progress);
  21. /** URL-encodes `s` */
  22. std::string encodeUrl(const std::string& s);
  23. /** Gets the path portion of the URL. */
  24. std::string urlPath(const std::string& url);
  25. } // namespace network
  26. } // namespace rack