@@ -13,7 +13,7 @@ A high-performance C++ HTTP/WebSocket client library built on Boost.Beast with f
1313- ** HTTP Streaming** : Support for Server-Sent Events (SSE) and chunked response streaming
1414- ** Asynchronous WebSocket Client** : Built on Boost.Asio coroutines for high-performance async operations
1515- ** SSL/TLS Support** : Native support for secure ` https:// ` and ` wss:// ` connections
16- - ** Synchronous & Asynchronous APIs** : Both blocking and non-blocking HTTP operations
16+ - ** Multiple Async APIs** : Synchronous, callback-based, and C++20 coroutine awaitable interfaces
1717- ** Cross-Platform** : Works on Windows, Linux, and macOS
1818- ** Header-Only** : Easy integration with minimal dependencies
1919- ** Callback-Based API** : Clean event-driven interface for connection lifecycle management
@@ -156,6 +156,7 @@ Run examples:
156156./examples/websocket_client_example
157157./examples/http_client_example
158158./examples/http_stream_client_example
159+ ./examples/http_awaitable_client_example
159160```
160161
161162## API Reference
@@ -171,7 +172,7 @@ Http::Response patch(std::string_view url, std::string_view data, std::vector<st
171172Http::Response del(std::string_view url, std::string_view data, std::vector<std::pair<std::string, std::string>>&& headers = {});
172173```
173174
174- **Asynchronous Methods:**
175+ **Asynchronous Callback-Based Methods:**
175176```cpp
176177void async_get(std::function<void(Response&&)> on_response, std::string_view url, std::vector<std::pair<std::string, std::string>>&& headers = {});
177178void async_post(std::function<void(Response&&)> on_response, std::string_view url, std::string_view data, std::vector<std::pair<std::string, std::string>>&& headers = {});
@@ -180,6 +181,15 @@ void async_patch(std::function<void(Response&&)> on_response, std::string_view u
180181void async_del(std::function<void(Response&&)> on_response, std::string_view url, std::string_view data, std::vector<std::pair<std::string, std::string>>&& headers = {});
181182```
182183
184+ ** Asynchronous Awaitable Methods (C++20 Coroutines):**
185+ ``` cpp
186+ asio::awaitable<Response> async_get (std::string_view url, std::vector<std::pair<std::string, std::string>>&& headers = {});
187+ asio::awaitable<Response > async_post(std::string_view url, std::string_view data, std::vector<std::pair<std::string, std::string>>&& headers = {});
188+ asio::awaitable<Response > async_put(std::string_view url, std::string_view data, std::vector<std::pair<std::string, std::string>>&& headers = {});
189+ asio::awaitable<Response > async_patch(std::string_view url, std::string_view data, std::vector<std::pair<std::string, std::string>>&& headers = {});
190+ asio::awaitable<Response > async_del(std::string_view url, std::string_view data = "", std::vector<std::pair<std::string, std::string>>&& headers = {});
191+ ```
192+
183193**Response Structure:**
184194```cpp
185195struct Response {
@@ -189,7 +199,7 @@ struct Response {
189199};
190200```
191201
192- **Example Usage:**
202+ ** Example Usage - Synchronous :**
193203``` cpp
194204#include < slick/net/http.h>
195205
@@ -198,6 +208,11 @@ auto response = Http::get("https://api.example.com/data");
198208if (response.is_ok()) {
199209 std::cout << response.result_text << std::endl;
200210}
211+ ```
212+
213+ ** Example Usage - Asynchronous Callback-Based:**
214+ ``` cpp
215+ #include < slick/net/http.h>
201216
202217// Asynchronous POST with JSON
203218nlohmann::json data = {{"key", "value"}};
@@ -208,6 +223,41 @@ Http::async_post([](Http::Response&& rsp) {
208223}, "https://api.example.com/resource ", data.dump(), {{"Content-Type", "application/json"}});
209224```
210225
226+ **Example Usage - Asynchronous Awaitable (C++20 Coroutines):**
227+ ```cpp
228+ #include <slick/net/http.h>
229+ #include <boost/asio.hpp>
230+
231+ asio::awaitable<void> fetch_data() {
232+ // Awaitable GET - clean async/await syntax
233+ auto response = co_await Http::async_get("https://api.example.com/data");
234+ if (response.is_ok()) {
235+ std::cout << "Response: " << response.result_text << std::endl;
236+ }
237+
238+ // Sequential requests
239+ nlohmann::json post_data = {{"key", "value"}};
240+ auto post_response = co_await Http::async_post(
241+ "https://api.example.com/resource",
242+ post_data.dump(),
243+ {{"Content-Type", "application/json"}}
244+ );
245+
246+ if (post_response.is_ok()) {
247+ std::cout << "Created: " << post_response.result_text << std::endl;
248+ }
249+ }
250+
251+ int main() {
252+ asio::io_context ioc;
253+
254+ asio::co_spawn(ioc, fetch_data(), asio::detached);
255+
256+ ioc.run();
257+ return 0;
258+ }
259+ ```
260+
211261### Websocket Class
212262
213263** Constructor:**
0 commit comments