HTTP Client Skill
Make outbound HTTP requests from the device using the URL module with simple and streaming APIs.
Invoke with: /http
Key APIs
c
/* Simple one-call functions (return allocated data, caller frees) */
char *urlGet(cchar *url, cchar *headers, ...);
char *urlPost(cchar *url, cvoid *data, size_t size, cchar *headers, ...);
Json *urlGetJson(cchar *url, cchar *headers, ...);
Json *urlPostJson(cchar *url, cvoid *data, ssize len, cchar *headers, ...);
/* Streaming with explicit Url object */
Url *urlAlloc(int flags);
int urlFetch(Url *up, cchar *method, cchar *url, cvoid *data, size_t size, cchar *headers, ...);
ssize urlRead(Url *up, char *buf, size_t bufsize);
void urlFree(Url *up);Simple GET
c
char *data = urlGet("https://api.example.com/data", NULL);
rPrintf("Response: %s\n", data);
rFree(data);JSON GET/POST
c
/* GET with JSON response */
Json *json = urlGetJson("https://api.example.com/status", NULL);
cchar *state = jsonGet(json, "state");
jsonFree(json);
/* POST JSON */
char *body = sfmt("{\"temp\": \"23.5\"}");
Json *result = urlPostJson("https://api.example.com/data", body, slen(body),
"Content-Type: application/json\r\n");
rFree(body);
jsonFree(result);Streaming Fetch
c
Url *up;
char buf[1024];
ssize nbytes;
up = urlAlloc(0);
urlFetch(up, "GET", "https://example.com/stream", NULL, 0, NULL);
while ((nbytes = urlRead(up, buf, sizeof(buf))) > 0) {
/* process chunk */
}
urlFree(up);Important Notes
urlGet()andurlPost()return allocated strings — caller mustrFree().urlGetJson()andurlPostJson()return Json objects — caller mustjsonFree().- All URL calls are fiber-aware and yield while waiting for I/O.
