Add simplified client API (http_get, http_put, http_post, http_delete)

This commit is contained in:
2025-11-27 09:50:41 +01:00
parent 6a9ba6bbf4
commit 1ef6187b2d
6 changed files with 206 additions and 28 deletions
+40
View File
@@ -0,0 +1,40 @@
#include "../chttp.h"
int main(void)
{
int ret;
HTTP_Client client;
ret = http_client_init(&client);
if (ret < 0) {
printf("Couldn't initialize client (%s)\n", http_strerror(ret));
return -1;
}
HTTP_RequestBuilder builder = http_client_get_builder(&client);
http_request_builder_method(builder, HTTP_METHOD_GET);
http_request_builder_target(builder, HTTP_STR("http://coz.is"));
http_request_builder_header(builder, HTTP_STR("Greeting: Hello from the cHTTP example!"));
ret = http_request_builder_send(builder);
if (ret < 0) {
printf("Couldn't build request (%s)\n", http_strerror(ret));
return -1;
}
int result;
void *user;
HTTP_Response *response;
http_client_wait_response(&client, &result, &user, &response);
if (result == HTTP_OK) {
printf("Received %d bytes\n", response->body.len);
} else {
printf("Couldn't receive response (%s)\n", http_strerror(result));
}
http_free_response(response);
http_client_free(&client);
return 0;
}