http client first version made by claude opus
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
// ── Result Types ────────────────────────────────────────────────────────────
|
||||
|
||||
// Text/JSON response. Caller must free(body) after use.
|
||||
struct http_text_response_t
|
||||
{
|
||||
int status_code; // HTTP status (200, 404, 500, …)
|
||||
char *body; // Heap-allocated, null-terminated
|
||||
size_t body_len; // Byte length (excluding null terminator)
|
||||
};
|
||||
|
||||
// Binary response (e.g. PNG image). Caller must free(data) after use.
|
||||
struct http_binary_response_t
|
||||
{
|
||||
int status_code;
|
||||
uint8_t *data; // Heap-allocated binary buffer
|
||||
size_t data_len; // Byte length
|
||||
};
|
||||
|
||||
// ── Functions ───────────────────────────────────────────────────────────────
|
||||
|
||||
// Build "http://<host>:<port><path>".
|
||||
// Returns a heap-allocated string; caller must free().
|
||||
char *http_build_url(const char *host, uint16_t port, const char *path);
|
||||
|
||||
// GET a text/JSON resource. Blocks until complete.
|
||||
// On success (ESP_OK): out is filled. Caller must free(out->body).
|
||||
// On failure: out is zeroed, returns an esp_err_t.
|
||||
esp_err_t http_get_text(const char *url, http_text_response_t *out);
|
||||
|
||||
// GET a binary resource (e.g. PNG image). Blocks until complete.
|
||||
// On success (ESP_OK): out is filled. Caller must free(out->data).
|
||||
// On failure: out is zeroed, returns an esp_err_t.
|
||||
esp_err_t http_get_binary(const char *url, http_binary_response_t *out);
|
||||
|
||||
// POST a JSON body, receive a JSON response. Blocks until complete.
|
||||
// json_body must be a null-terminated JSON string.
|
||||
// On success (ESP_OK): out is filled. Caller must free(out->body).
|
||||
// On failure: out is zeroed, returns an esp_err_t.
|
||||
esp_err_t http_post_json(const char *url, const char *json_body,
|
||||
http_text_response_t *out);
|
||||
Reference in New Issue
Block a user