Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
http_facade_example.cpp
Go to the documentation of this file.
1/*****************************************************************************
2BSD 3-Clause License
3
4Copyright (c) 2024, 🍀☀🌕🌥 🌊
5All rights reserved.
6*****************************************************************************/
7
25
26#include <iostream>
27#include <string>
28
29using namespace kcenon::network;
30
31int main()
32{
33 std::cout << "=== HTTP Facade Example ===" << std::endl;
34
35 // Server configuration
37 srv_config.port = 8080;
38 srv_config.server_id = "example-http-server";
39
40 std::cout << "\n1. Creating HTTP server..." << std::endl;
41 std::cout << " Port: " << srv_config.port << std::endl;
42 std::cout << " Server ID: " << srv_config.server_id << std::endl;
43
44 auto server = facade::http_facade::create_server(srv_config);
45 if (server)
46 {
47 std::cout << " Server created successfully" << std::endl;
48 }
49 else
50 {
51 std::cout << " Server creation returned null (expected in demo)" << std::endl;
52 }
53
54 // Client configuration
56 cli_config.client_id = "example-http-client";
57 cli_config.timeout = std::chrono::seconds(30);
58 cli_config.use_ssl = false;
59
60 std::cout << "\n2. Creating HTTP client..." << std::endl;
61 std::cout << " Client ID: " << cli_config.client_id << std::endl;
62 std::cout << " Timeout: " << cli_config.timeout.count() << "ms" << std::endl;
63 std::cout << " SSL: " << (cli_config.use_ssl ? "enabled" : "disabled") << std::endl;
64
65 auto client = facade::http_facade::create_client(cli_config);
66 if (client)
67 {
68 std::cout << " Client created successfully" << std::endl;
69 }
70 else
71 {
72 std::cout << " Client creation returned null (expected in demo)" << std::endl;
73 }
74
75 std::cout << "\nDone." << std::endl;
76 return 0;
77}
auto create_server(const server_config &config) const -> Result< std::shared_ptr< interfaces::i_protocol_server > >
Creates an HTTP server with the specified configuration.
auto create_client(const client_config &config) const -> Result< std::shared_ptr< interfaces::i_protocol_client > >
Creates an HTTP client with the specified configuration.
Simplified facade for creating HTTP clients and servers.
int main()
Main namespace for all Network System components.
Configuration for creating an HTTP client.
Definition http_facade.h:84
std::string client_id
Client identifier (auto-generated if not provided)
Definition http_facade.h:86
std::chrono::milliseconds timeout
Request timeout.
Definition http_facade.h:89
Configuration for creating an HTTP server.
std::string server_id
Server identifier (optional, auto-generated if not provided)