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.

35 lines
769B

  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. /** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc)
  15. Caller must json_decref().
  16. */
  17. json_t* requestJson(Method method, std::string url, json_t* dataJ);
  18. /** Returns true if downloaded successfully */
  19. bool requestDownload(std::string url, const std::string& filename, float* progress);
  20. /** URL-encodes `s` */
  21. std::string encodeUrl(const std::string& s);
  22. /** Gets the path portion of the URL. */
  23. std::string urlPath(const std::string& url);
  24. } // namespace network
  25. } // namespace rack