VCV Rack API v2
rack::network Namespace Reference

Networking functions for HTTP requests, downloads, and URLs. More...

Typedefs

typedef std::map< std::string, std::string > CookieMap
 

Enumerations

enum  Method { METHOD_GET , METHOD_POST , METHOD_PUT , METHOD_DELETE }
 

Functions

PRIVATE void init ()
 
PRIVATE void destroy ()
 
json_t * requestJson (Method method, const std::string &url, json_t *dataJ=NULL, const CookieMap &cookies={})
 Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc) Caller must json_decref() if return value is non-NULL. More...
 
bool requestDownload (const std::string &url, const std::string &filename, float *progress, const CookieMap &cookies={})
 Returns true if downloaded successfully. More...
 
std::string encodeUrl (const std::string &s)
 URL-encodes a string. More...
 
std::string urlPath (const std::string &url)
 Returns the path portion of the URL. More...
 

Detailed Description

Networking functions for HTTP requests, downloads, and URLs.

Typedef Documentation

◆ CookieMap

typedef std::map<std::string, std::string> rack::network::CookieMap

Enumeration Type Documentation

◆ Method

Enumerator
METHOD_GET 
METHOD_POST 
METHOD_PUT 
METHOD_DELETE 

Function Documentation

◆ init()

PRIVATE void rack::network::init ( )

◆ destroy()

PRIVATE void rack::network::destroy ( )

◆ requestJson()

json_t * rack::network::requestJson ( Method  method,
const std::string &  url,
json_t *  dataJ = NULL,
const CookieMap cookies = {} 
)

Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc) Caller must json_decref() if return value is non-NULL.

◆ requestDownload()

bool rack::network::requestDownload ( const std::string &  url,
const std::string &  filename,
float *  progress,
const CookieMap cookies = {} 
)

Returns true if downloaded successfully.

If progress is non-NULL, the value is updated from 0 to 1 while downloading.

◆ encodeUrl()

std::string rack::network::encodeUrl ( const std::string &  s)

URL-encodes a string.

◆ urlPath()

std::string rack::network::urlPath ( const std::string &  url)

Returns the path portion of the URL.

Example:

urlPath("https://example.com/foo/index.html") // Returns "/foo/index.html"