16#include <ove/net_http.h>
19#ifdef CONFIG_OVE_NET_HTTP
53 ~Response() { ove_http_response_free(&raw_); }
55 Response(
const Response &) =
delete;
56 Response &operator=(
const Response &) =
delete;
62 Response(Response &&other) noexcept : raw_(other.raw_) {
71 Response &operator=(Response &&other)
noexcept {
73 ove_http_response_free(&raw_);
81 int status()
const {
return raw_.status; }
84 const char *body()
const {
return raw_.body; }
87 size_t body_len()
const {
return raw_.body_len; }
90 const char *headers()
const {
return raw_.headers; }
93 size_t headers_len()
const {
return raw_.headers_len; }
99 ove_http_response_t *raw() {
return &raw_; }
101 ove_http_response_t raw_{};
124#ifdef CONFIG_OVE_ZERO_HEAP
125 int err = ove_http_client_init(&handle_, &storage_);
127 int err = ove_http_client_create(&handle_);
129 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
138 if (!handle_)
return;
139#ifdef CONFIG_OVE_ZERO_HEAP
140 ove_http_client_deinit(handle_);
142 ove_http_client_destroy(handle_);
146 Client(
const Client &) =
delete;
147 Client &operator=(
const Client &) =
delete;
149#ifdef CONFIG_OVE_ZERO_HEAP
150 Client(Client &&) =
delete;
151 Client &operator=(Client &&) =
delete;
157 Client(Client &&other) noexcept : handle_(other.handle_) {
158 other.handle_ =
nullptr;
166 Client &operator=(Client &&other)
noexcept {
167 if (
this != &other) {
168 if (handle_) ove_http_client_destroy(handle_);
169 handle_ = other.handle_;
170 other.handle_ =
nullptr;
182 [[nodiscard]]
int get(
const char *url, Response &resp) {
183 return ove_http_get(handle_, url, &resp.raw_);
195 [[nodiscard]]
int post(
const char *url,
const char *content_type,
196 const void *body,
size_t body_len,
198 return ove_http_post(handle_, url, content_type,
199 body, body_len, &resp.raw_);
212 [[nodiscard]]
int request(ove_http_method_t method,
const char *url,
213 const char *content_type,
214 const void *body,
size_t body_len,
216 return ove_http_request(handle_, method, url, content_type,
217 body, body_len, &resp.raw_);
232 [[nodiscard]]
int request(ove_http_method_t method,
const char *url,
233 const char *content_type,
234 const void *body,
size_t body_len,
235 const ove_http_header_t *headers,
238 return ove_http_request_ex(handle_, method, url, content_type,
239 body, body_len, headers,
240 header_count, &resp.raw_);
247 bool valid()
const {
return handle_ !=
nullptr; }
253 ove_http_client_t handle()
const {
return handle_; }
256 ove_http_client_t handle_ =
nullptr;
257#ifdef CONFIG_OVE_ZERO_HEAP
258 ove_http_client_storage_t storage_ = {};
int get(unsigned int port, unsigned int pin)
Reads the current logic level of a GPIO pin.
Definition gpio.hpp:62
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.