### start() Source: https://crowcpp.org/master/reference/functions_s.html Starts a websocket connection. ```APIDOC ## start() ### Description Initiates or starts the websocket connection. ### Method N/A (Function) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### start() Source: https://crowcpp.org/master/reference/structcrow_1_1_s_s_l_adaptor-members.html Starts the SSL handshake process. ```APIDOC ## start(F f) ### Description Starts the SSL handshake process with the given callback function `f`. ### Method start ### Parameters - **f** (F) - The callback function to be invoked upon completion of the handshake. ``` -------------------------------- ### Start Main Server Loop Source: https://crowcpp.org/master/reference/http__server_8h_source.html Initiates the server's accept loop to start handling incoming connections. ```cpp do_accept(); ``` -------------------------------- ### start Source: https://crowcpp.org/master/reference/structcrow_1_1_unix_socket_adaptor.html Starts an asynchronous operation on the socket. ```APIDOC ## start ### Description Initiates an asynchronous operation, typically for accepting connections or handling data, with a provided callback function. ### Parameters * **f** (F) - A callable object (function or lambda) that will be invoked upon completion of the asynchronous operation. ``` -------------------------------- ### Wait for Start Source: https://crowcpp.org/master/reference/functions_func.html Blocks until the server has started. ```APIDOC ## wait_for_start() ### Description Blocks execution until the server has successfully started. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters None ``` -------------------------------- ### Basic Crow Application Setup Source: https://crowcpp.org/master This snippet demonstrates the basic setup for a Crow application, including including the necessary header, initializing the app, defining a root route, and running the server on a specified port. ```cpp #include "crow.h" int main() { crow::SimpleApp app; CROW_ROUTE(app, "/")([](){ return "Hello world"; }); app.port(18080).run(); } ``` -------------------------------- ### run Source: https://crowcpp.org/master/reference/classcrow_1_1_server.html Starts the server and begins listening for incoming connections. ```APIDOC ## run ### Description Starts the HTTP server, making it ready to accept incoming requests. ### Method void ``` -------------------------------- ### WebSocket Connection Start Source: https://crowcpp.org/master/reference/functions_func.html Starts a WebSocket connection. ```APIDOC ## start() ### Description Initiates the WebSocket connection handshake and begins message handling. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters None ``` -------------------------------- ### start Source: https://crowcpp.org/master/reference/structcrow_1_1_socket_adaptor.html Starts an asynchronous operation on the socket with a given handler. ```APIDOC ## start ### Description Starts an asynchronous operation on the socket with a given handler. ### Parameters - **f** (F) - A callable object (function, lambda, etc.) that will be invoked when the operation completes. ``` -------------------------------- ### Build and Install Crow with SBOM Source: https://crowcpp.org/master/guides/sbom Builds the Crow project and installs it, which triggers the generation of the .spdx SBOM file in the build directory. The file name follows the pattern `crow--.spdx`. ```bash cmake --build . cmake --install . --prefix /tmp/crow-install ``` -------------------------------- ### run Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Starts the Crow server and begins handling requests. ```APIDOC ## run ### Description Run the server. ``` -------------------------------- ### start() Source: https://crowcpp.org/master/reference/classcrow_1_1websocket_1_1_connection.html Protected method to initiate the WebSocket handshake response and begin reading messages. It sends the HTTP upgrade response and then starts the message reading loop. ```APIDOC ## start() ### Description Send the HTTP upgrade response. Finishes the handshake process, then starts reading messages from the socket. ### Parameters - `_hello_` (std::string &&) - An rvalue reference to a string, potentially used for initial handshake data. ### Method protected ``` -------------------------------- ### Start Main IO Context in a New Thread Source: https://crowcpp.org/master/reference/http__server_8h_source.html Starts the main io_context in a separate thread, logs an exit message when done, and joins the thread. ```cpp std::thread( [this] { notify_start(); io_context_.run(); CROW_LOG_INFO << "Exiting."; }) .join(); ``` -------------------------------- ### run() Source: https://crowcpp.org/master/reference/app_8h_source.html Starts the server and begins listening for incoming connections. This is a blocking call. ```APIDOC ## run() ### Description Starts the server and begins listening for incoming connections. This is a blocking call. ### Method `void run()` ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```cpp app.run(); ``` ### Response None ``` -------------------------------- ### start(F f) Source: https://crowcpp.org/master/reference/structcrow_1_1_unix_socket_adaptor-members.html Starts an asynchronous operation on the socket with the given handler. ```APIDOC ## start(F f) ### Description Starts an asynchronous operation on the socket with the given handler. ### Method `inline` ### Endpoint N/A ### Parameters - **f** (F) - The handler function for the asynchronous operation. ### Request Example None ### Response #### Success Response None ### Response Example None ``` -------------------------------- ### Run Server Source: https://crowcpp.org/master/reference/functions_func.html Starts the Crow server and begins listening for incoming requests. ```APIDOC ## run() ### Description Starts the Crow web server and blocks until the server is stopped. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None (Server runs indefinitely until stopped). ``` -------------------------------- ### Wait for Server Start Source: https://crowcpp.org/master/reference/functions_func.html Blocks until the Crow server has started. ```APIDOC ## wait_for_server_start() ### Description Blocks execution until the Crow server has successfully started and is ready to accept connections. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters None ``` -------------------------------- ### Install Crow using VCPKG Source: https://crowcpp.org/master/getting_started/setup/windows Use this command to install Crow via the VCPKG package manager. Ensure VCPKG is set up in your environment. ```bash vcpkg install crow ``` -------------------------------- ### start Source: https://crowcpp.org/master/reference/websocket_8h_source.html Completes the WebSocket handshake and begins reading messages from the socket. ```APIDOC ## start ### Description Completes the WebSocket handshake by sending the upgrade response and then starts reading messages from the socket. It also triggers the open handler if one is set. ### Method void start(std::string&& hello) ### Parameters - **hello** (std::string&&) - The content for the Sec-WebSocket-Accept header. ``` -------------------------------- ### Build Crow Tests and Examples with CMake Source: https://crowcpp.org/master/getting_started/setup/macos Builds Crow's tests and examples using CMake. This involves creating a build directory, configuring with CMake, and then compiling. ```bash mkdir build ``` ```bash cd build ``` ```bash cmake .. ``` ```bash make -j12 ``` -------------------------------- ### wait_for_start Source: https://crowcpp.org/master/reference/functions_w.html Waits for the server to start, with configurable handler, acceptor, adaptor, and middlewares. ```APIDOC ## wait_for_start() : crow::Server< Handler, Acceptor, Adaptor, Middlewares > ### Description This function is part of the crow::Server class and is used to wait for the server to begin its execution. It is templated to allow for custom configurations of Handlers, Acceptors, Adaptors, and Middlewares. ### Method (Not specified, likely a member function) ### Endpoint (Not applicable, this is a function call) ### Parameters (None specified, configuration is via template parameters) ### Request Example (Not applicable) ### Response Returns an instance of crow::Server with the specified template parameters, indicating the server is ready or has started. ``` -------------------------------- ### crow::Crow< Middlewares >::run Source: https://crowcpp.org/master/reference/functions_r.html Starts the Crow web server and begins listening for incoming requests. ```APIDOC ## run() ### Description Starts the Crow application's HTTP server, making it listen for and process incoming requests synchronously. ### Method N/A (Class Member Function) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - The server runs indefinitely until stopped externally or an unhandled exception occurs. ``` -------------------------------- ### wait_for_server_start Source: https://crowcpp.org/master/reference/functions_w.html Waits for the Crow server to start. ```APIDOC ## wait_for_server_start() ### Description Waits for the Crow server to initiate its operations. ### Method (Not specified, likely a member function) ### Endpoint (Not applicable, this is a function call) ### Parameters (None specified) ### Request Example (Not applicable) ### Response (Not specified, likely returns void or a status indicator) ``` -------------------------------- ### Start SSL Handshake Source: https://crowcpp.org/master/reference/socket__adaptors_8h_source.html Initiates an asynchronous SSL handshake for the server. ```cpp template void start(F f) { ssl_socket_->async_handshake(asio::ssl::stream_base::server, [f](const error_code& ec) { f(ec); }); } ``` -------------------------------- ### WebSocket Event Handlers Example Source: https://crowcpp.org/master/reference/app_8h_source.html Example of defining onclose and onmessage handlers for a WebSocket connection. ```cpp .onclose([&](crow::websocket::connection& conn, const std::string& reason, uint16_t){ do_something(); }) .onmessage([&](crow::websocket::connection&, const std::string& data, bool is_binary){ if (is_binary) do_something(data); else do_something_else(data); }); ``` -------------------------------- ### Wait for Server Start Source: https://crowcpp.org/master/reference/http__server_8h_source.html Blocks until the server has started or the specified timeout is reached. Useful for synchronization. ```cpp std::cv_status Server::wait_for_start(std::chrono::steady_clock::time_point wait_until) { std::unique_lock lock(start_mutex_); return cv_started_.wait_until(lock, wait_until, [this]{ return server_started_; }); } ``` -------------------------------- ### crow::Crow::run Source: https://crowcpp.org/master/reference/app_8h_source.html Starts and runs the Crow server. ```APIDOC ## crow::Crow::run ### Description Runs the server. ### Method `void run()` ``` -------------------------------- ### Install Python Packages for SBOM Source: https://crowcpp.org/master/guides/sbom Installs the necessary Python packages for SBOM generation into a virtual environment. Ensure you activate the virtual environment before running this command. ```bash pip install spdx-tools reuse ntia-conformance-checker ``` -------------------------------- ### Wait for Server Start Source: https://crowcpp.org/master/reference/http__server_8h_source.html Blocks until the server has started or a specified timeout is reached. Uses a condition variable for synchronization. ```cpp std::cv_status wait_for_start(std::chrono::steady_clock::time_point wait_until) { std::unique_lock lock(start_mutex_); std::cv_status status = std::cv_status::no_timeout; while (!server_started_ && !startup_failed_ && status == std::cv_status::no_timeout) status = cv_started_.wait_until(lock, wait_until); return status; } ``` -------------------------------- ### run_async() Source: https://crowcpp.org/master/reference/app_8h_source.html Starts the server in a non-blocking manner, returning a future that can be used to track its completion. ```APIDOC ## run_async() ### Description Starts the server in a non-blocking manner, returning a future that can be used to track its completion. ### Method `std::future run_async()` ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```cpp auto future = app.run_async(); // ... do other work ... future.get(); // Wait for server to finish if needed ``` ### Response `std::future`: A future object that will be ready when the server stops. ``` -------------------------------- ### wait_for_start Source: https://crowcpp.org/master/reference/classcrow_1_1_server.html Waits until the server has started or until a specified timeout. ```APIDOC ## wait_for_start ### Description Waits until the server has properly started or until the specified timeout is reached. ### Parameters - **wait_until** (std::chrono::steady_clock::time_point) - The time point until which to wait. ### Returns A std::cv_status indicating whether the condition was met or a timeout occurred. ``` -------------------------------- ### Server Run Source: https://crowcpp.org/master/reference/app_8h_source.html Starts the Crow server, applying blueprints and static directories before validation and execution. ```APIDOC ## run() ### Description Starts the Crow server. It first applies blueprints and sets up the static directory (if not disabled), then validates the router, and finally starts the SSL server if SSL is enabled and configured. ### Method `run` ``` -------------------------------- ### crow::Server::wait_for_start Source: https://crowcpp.org/master/reference/classcrow_1_1_server-members.html Waits until a specified time point for the server to start. ```APIDOC ## wait_for_start() ### Description Blocks execution until the server has started or a specified time is reached. ### Method `wait_for_start(std::chrono::steady_clock::time_point wait_until)` ### Parameters * **wait_until** (std::chrono::steady_clock::time_point) - The time point to wait until. ``` -------------------------------- ### Specify HTTP Methods for a Route Source: https://crowcpp.org/master/guides/routes Extend the CROW_ROUTE macro using .methods() to specify which HTTP methods a route should respond to. This example shows how to allow both GET and PATCH requests. ```cpp CROW_ROUTE(app, "/add//").methods(crow::HTTPMethod::GET, crow::HTTPMethod::PATCH) ``` ```cpp CROW_ROUTE(app, "/add//").methods("GET"_method, "PATCH"_method) ``` -------------------------------- ### SSLAdaptor::start Source: https://crowcpp.org/master/reference/structcrow_1_1_s_s_l_adaptor.html Starts an asynchronous operation on the SSL socket. ```APIDOC ## SSLAdaptor::start ### Description Starts an asynchronous operation, typically a handshake or read/write operation, on the SSL socket. The provided callback function `f` is invoked upon completion. ### Signature `template void start(F f)` ### Parameters * `f`: A callable object (function, lambda, etc.) that will be executed when the asynchronous operation completes. ``` -------------------------------- ### wait_for_server_start Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Waits for the server to start within a specified timeout. ```APIDOC ## wait_for_server_start(std::chrono::milliseconds wait_timeout=std::chrono::milliseconds(3000)) ### Description Blocks execution until the Crow server has successfully started or until the specified timeout is reached. ### Method `wait_for_server_start(std::chrono::milliseconds wait_timeout)` ### Endpoint N/A (Method call) ### Parameters - **wait_timeout** (std::chrono::milliseconds) - The maximum time to wait for the server to start. Defaults to 3000 milliseconds (3 seconds). ### Request Example ```cpp app.wait_for_server_start(std::chrono::seconds(5)); // Wait up to 5 seconds ``` ### Response None. Throws an exception if the server does not start within the timeout. ``` -------------------------------- ### Get Compression Algorithm Source: https://crowcpp.org/master/reference/app_8h_source.html Retrieves the currently configured compression algorithm. ```cpp compression::algorithm compression_algorithm() { return comp_algorithm_; } ``` -------------------------------- ### Configure SSL Files (Certificate and Key) Source: https://crowcpp.org/master/reference/app_8h_source.html Sets up SSL for the server using separate certificate and private key files. It configures the SSL context with verification options and loads the specified files. ```cpp ssl_used_ = true; ssl_context_.set_verify_mode(asio::ssl::verify_peer); ssl_context_.set_verify_mode(asio::ssl::verify_client_once); ssl_context_.use_certificate_file(crt_filename, ssl_context_t::pem); ssl_context_.use_private_key_file(key_filename, ssl_context_t::pem); ssl_context_.set_options( asio::ssl::context::default_workarounds | asio::ssl::context::no_sslv2 | asio::ssl::context::no_sslv3); return *this; ``` -------------------------------- ### Complete 'Hello World' Crow Application Source: https://crowcpp.org/master/getting_started/your_first_application A full example combining app declaration, route definition, and running the application. Ensure you include the necessary Crow header. ```cpp #include "crow.h" //#include "crow_all.h" int main() { crow::SimpleApp app; //define your crow application //define your endpoint at the root directory CROW_ROUTE(app, "/")([](){ return "Hello world"; }); //set the port, set the app to run on multiple threads, and run the app app.port(18080).multithreaded().run(); } ``` -------------------------------- ### crow::Crow< Middlewares >::run_async Source: https://crowcpp.org/master/reference/functions_r.html Starts the Crow web server asynchronously. ```APIDOC ## run_async() ### Description Starts the Crow application's HTTP server in an asynchronous manner, allowing the calling thread to continue execution. ### Method N/A (Class Member Function) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - The server runs in the background. The calling thread is not blocked. ``` -------------------------------- ### stream_threshold (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Gets the current threshold for streaming responses. ```APIDOC ## stream_threshold() ### Description Retrieves the current size threshold in bytes used for determining whether to buffer or stream responses. ### Method `stream_threshold()` ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```cpp size_t current_threshold = app.stream_threshold(); ``` ### Response - **size_t**: The current streaming threshold in bytes. ``` -------------------------------- ### concurrency (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Gets the number of threads the server is currently using. ```APIDOC ## concurrency (get) ### Description Get the number of threads that server is using. ### Returns The number of threads the server is using. ``` -------------------------------- ### Configure SSL Chain Files (Certificate Chain and Key) Source: https://crowcpp.org/master/reference/app_8h_source.html Sets up SSL for the server using a certificate chain file and a separate private key file. This is common when intermediate certificates are provided separately. It configures the SSL context and loads the files. ```cpp ssl_used_ = true; ssl_context_.set_verify_mode(asio::ssl::verify_peer); ssl_context_.set_verify_mode(asio::ssl::verify_client_once); ssl_context_.use_certificate_chain_file(crt_filename); ssl_context_.use_private_key_file(key_filename, ssl_context_t::pem); ssl_context_.set_options( asio::ssl::context::default_workarounds | asio::ssl::context::no_sslv2 | asio::ssl::context::no_sslv3); return *this; ``` -------------------------------- ### local_socket_path (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Gets the path of the Unix domain socket being used. ```APIDOC ## local_socket_path (get) ### Description Get the unix domain socket path. ### Returns The path of the Unix domain socket. ``` -------------------------------- ### crow::Crow::wait_for_server_start Source: https://crowcpp.org/master/reference/app_8h_source.html Waits until the server has properly started, with an optional timeout. ```APIDOC ## crow::Crow::wait_for_server_start ### Description Waits until the server has properly started. ### Method `std::cv_status wait_for_server_start(std::chrono::milliseconds wait_timeout = std::chrono::milliseconds(3000))` ### Parameters * **wait_timeout** (std::chrono::milliseconds) - Optional timeout duration to wait for the server to start. Defaults to 3000 milliseconds. ``` -------------------------------- ### websocket_max_payload (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Gets the maximum payload size for WebSocket messages. ```APIDOC ## websocket_max_payload() ### Description Retrieves the currently configured maximum allowed size (in bytes) for incoming WebSocket messages. ### Method `websocket_max_payload()` ### Endpoint N/A (Method call) ### Parameters None ### Request Example ```cpp uint64_t max_size = app.websocket_max_payload(); ``` ### Response - **uint64_t**: The maximum payload size in bytes. ``` -------------------------------- ### run Source: https://crowcpp.org/master/reference/http__server_8h_source.html Starts the HTTP server's main event loop. It initializes worker threads and begins accepting connections. If the server startup failed, this method will abort. ```APIDOC ## run ### Description Starts the HTTP server's main event loop. It initializes worker threads and begins accepting connections. If the server startup failed, this method will abort. ``` -------------------------------- ### port (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Gets the port on which the Crow server is configured to handle requests. ```APIDOC ## port (get) ### Description Get the port that Crow will handle requests on. ### Returns The configured port number. ``` -------------------------------- ### Create Blueprint with Custom Templates Directory (No Custom Static) Source: https://crowcpp.org/master/guides/blueprints Initialize a blueprint with a custom templates directory while using the default static directory. Pass an empty string for the static directory. ```cpp crow::blueprint bp("prefix", "", "custom_templates"); ``` -------------------------------- ### websocket_max_payload (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Gets the default maximum payload size for WebSocket connections. ```APIDOC ## websocket_max_payload (get) ### Description Get the default max payload size for websockets. ### Returns The default maximum payload size in bytes. ``` -------------------------------- ### crow::Connection::start Source: https://crowcpp.org/master/reference/classcrow_1_1_connection.html Initiates the connection handling process. ```APIDOC ## start ### Description Initiates the connection handling process. ### Signature `void start()` ``` -------------------------------- ### bindaddr (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Gets the IP address on which the Crow server is configured to handle requests. ```APIDOC ## bindaddr (get) ### Description Get the address that Crow will handle requests on. ### Returns The configured IP address. ``` -------------------------------- ### Initiate Asynchronous Accept Source: https://crowcpp.org/master/reference/http__server_8h_source.html Starts the asynchronous accept process to handle new incoming connections. It picks an appropriate IO context and creates a new Connection object. ```cpp void do_accept() { if (!shutting_down_) { size_t context_idx = pick_io_context_idx(); asio::io_context& ic = *io_context_pool_[context_idx]; auto p = std::make_shared>( ic, handler_, server_name_, middlewares_, get_cached_date_str_pool_[context_idx], *task_timer_pool_[context_idx], adaptor_ctx_, task_queue_length_pool_[context_idx]); CROW_LOG_DEBUG << &ic << " {" << context_idx << "} queue length: " << task_queue_length_pool_[context_idx]; acceptor_.raw_acceptor().async_accept( p->socket(), ``` -------------------------------- ### crow::Server::run Source: https://crowcpp.org/master/reference/classcrow_1_1_server-members.html Starts the web server, making it listen for incoming connections and process requests. ```APIDOC ## run() ### Description Initiates the server's main loop to start accepting and handling client requests. ### Method `run()` ### Parameters None ``` -------------------------------- ### Notify Server Start Source: https://crowcpp.org/master/reference/http__server_8h_source.html Notifies all waiting threads that the server has started. Used in conjunction with `wait_for_start`. ```cpp void Server::notify_start() { std::unique_lock lock(start_mutex_); server_started_ = true; cv_started_.notify_all(); } ``` -------------------------------- ### Run Server with SSL Source: https://crowcpp.org/master/reference/app_8h_source.html Initializes and runs the Crow server, including setting up SSL if CROW_ENABLE_SSL is defined. It handles address binding, endpoint creation, and SSL context setup. ```cpp void run() { #ifndef CROW_DISABLE_STATIC_DIR add_blueprint(); add_static_dir(); #endif validate(); #ifdef CROW_ENABLE_SSL if (ssl_used_) { error_code ec; asio::ip::address addr = asio::ip::make_address(bindaddr_,ec); if (ec){ CROW_LOG_ERROR << ec.message() << " - Can not create valid ip address from string: \"" << bindaddr_ << "\""; return; } tcp::endpoint endpoint(addr, port_); router_.using_ssl = true; ssl_server_ = std::move(std::unique_ptr(new ssl_server_t(this, endpoint, server_name_, &middlewares_, concurrency_, timeout_, &ssl_context_))); ``` -------------------------------- ### Configure SSL with .crt and .key files Source: https://crowcpp.org/master/guides/ssl Use this method to configure SSL when you have separate certificate and key files. This can be part of the app method chain. ```cpp app.ssl_file("/path/to/cert.crt", "/path/to/keyfile.key") ``` -------------------------------- ### stream_threshold (get) Source: https://crowcpp.org/master/reference/classcrow_1_1_crow.html Gets the response body size threshold (in bytes) beyond which Crow automatically streams responses. ```APIDOC ## stream_threshold (get) ### Description Get the response body size (in bytes) beyond which Crow automatically streams responses. ### Returns The response body size threshold in bytes. ``` -------------------------------- ### Start Parsing Header Field Source: https://crowcpp.org/master/reference/http__parser__merged_8h_source.html Initiates the parsing of a header field. Handles CR/LF for end of headers and identifies the start of a new header token. ```cpp case s_header_field_start: { if (ch == cr) { parser->state = s_headers_almost_done; break; } if (ch == lf) { /* they might be just sending \n instead of \r\n so this would be * the second \n to denote the end of headers*/ parser->state = s_headers_almost_done; CROW_REEXECUTE(); } c = CROW_TOKEN(ch); if (CROW_UNLIKELY(!c)) { CROW_SET_ERRNO(CHPE_INVALID_HEADER_TOKEN); goto error; } CROW_MARK(header_field); parser->index = 0; parser->state = s_header_field; switch (c) { case 'c': parser->header_state = h_C; break; case 'p': parser->header_state = h_matching_proxy_connection; break; case 't': parser->header_state = h_matching_transfer_encoding; break; case 'u': parser->header_state = h_matching_upgrade; break; default: parser->header_state = h_general; break; } break; } ``` -------------------------------- ### HTTP Request Format Example Source: https://crowcpp.org/master/guides/testing Illustrates the standard format for constructing an HTTP request string, including method, path, headers, and body. ```text METHOD /\r\nContent-Length:123\r\nheader1:value1\r\nheader2:value2\r\n\r\nBODY\r\n ``` -------------------------------- ### Integrate VCPKG with Visual Studio Source: https://crowcpp.org/master/getting_started/setup/windows Integrate VCPKG with your Visual Studio installation. This allows Visual Studio to find and use packages installed by VCPKG. ```bash .\vcpkg\vcpkg integrate install ``` -------------------------------- ### Create a Blueprint with a Prefix Source: https://crowcpp.org/master/guides/blueprints Initialize a blueprint with a prefix. All routes defined within this blueprint will be prepended with this prefix. ```cpp crow::blueprint bp("prefix"); ``` -------------------------------- ### Create Blueprint with Custom Templates Directory Source: https://crowcpp.org/master/guides/blueprints Initialize a blueprint with custom static and template directories. Routes within this blueprint will use the specified template directory. ```cpp crow::blueprint bp("prefix", "custom_static", "custom_templates"); ``` -------------------------------- ### Add Blueprints with Static Directories Source: https://crowcpp.org/master/reference/app_8h_source.html Applies blueprints to the router, setting up static file serving for each. Blueprints with empty static directories are ignored with an error log. ```cpp void add_blueprint() { #if defined(__APPLE__) || defined(__MACH__) if (router_.blueprints().empty()) return; #endif for (Blueprint* bp : router_.blueprints()) { if (bp->static_dir().empty()) { CROW_LOG_ERROR << "Blueprint " << bp->prefix() << " and its sub-blueprints ignored due to empty static directory."; continue; } auto static_dir_ = crow::utility::normalize_path(bp->static_dir()); bp->new_rule_tagged(CROW_STATIC_ENDPOINT)([static_dir_](crow::response& res, std::string file_path_partial) { utility::sanitize_filename(file_path_partial); res.set_static_file_info_unsafe(static_dir_ + file_path_partial); res.end(); }); } router_.validate_bp(); } ``` -------------------------------- ### Wait for Server Start Source: https://crowcpp.org/master/reference/app_8h_source.html Blocks execution until the server has fully started or a timeout occurs. It checks internal server state and the state of the underlying server implementation (TCP, Unix, or SSL). ```cpp std::cv_status wait_for_server_start(std::chrono::milliseconds wait_timeout = std::chrono::milliseconds(3000)) { std::cv_status status = std::cv_status::no_timeout; auto wait_until = std::chrono::steady_clock::now() + wait_timeout; { std::unique_lock lock(start_mutex_); while (!server_started_ && (status == std::cv_status::no_timeout)) { status = cv_started_.wait_until(lock, wait_until); } } if (status == std::cv_status::no_timeout) { if (server_) { status = server_->wait_for_start(wait_until); } else if (unix_server_) { status = unix_server_->wait_for_start(wait_until); } #ifdef CROW_ENABLE_SSL else if (ssl_server_) { status = ssl_server_->wait_for_start(wait_until); } #endif } return status; } ``` -------------------------------- ### Initialize wvalue as an object with an initializer list Source: https://crowcpp.org/master/guides/json Demonstrates initializing a wvalue as an object using an initializer list. This is a concise way to create JSON objects with predefined key-value pairs. ```cpp crow::json::wvalue x = {{"a", 1}, {"b", 2}}; ``` -------------------------------- ### opcode() Source: https://crowcpp.org/master/reference/functions_func.html Gets the opcode of a websocket frame. ```APIDOC ## opcode() ### Description Retrieves the opcode of the current websocket frame. ### Method Not specified (likely a member function) ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response Returns crow::websocket::Connection< Adaptor, Handler >. ``` -------------------------------- ### Server Constructor Source: https://crowcpp.org/master/reference/classcrow_1_1_server.html Initializes a new instance of the Server class with specified handler, endpoint, server name, middlewares, concurrency, timeout, and adaptor context. ```APIDOC ## Server Constructor ### Description Initializes a new instance of the Server class. ### Parameters - **handler** (Handler *) - The handler to be used by the server. - **endpoint** (Acceptor::endpoint) - The network endpoint for the server. - **server_name** (std::string) - Optional name for the server, defaults to "Crow/" + VERSION. - **middlewares** (std::tuple *) - Optional tuple of middlewares to apply. - **concurrency** (unsigned int) - Optional number of concurrent threads, defaults to 1. - **timeout** (uint8_t) - Optional timeout value in seconds, defaults to 5. - **adaptor_ctx** (Adaptor::context *) - Optional context for the adaptor. ``` -------------------------------- ### get() Source: https://crowcpp.org/master/reference/functions_func.html Retrieves a value from a query string. ```APIDOC ## get() ### Description Retrieves a value from the query string. ### Method Not specified (likely a member function) ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response Returns crow::query_string. ``` -------------------------------- ### Bootstrap VCPKG Source: https://crowcpp.org/master/getting_started/setup/windows Run the VCPKG bootstrap script to set up VCPKG for use on your Windows system. This script prepares VCPKG for installation and integration. ```bash .\vcpkg\bootstrap-vcpkg.bat ``` -------------------------------- ### Enable HTTP Compression with G++ Source: https://crowcpp.org/master/guides/compression Example of compiling a Crow application with HTTP compression enabled using g++. Ensure ZLIB is linked. ```bash g++ main.cpp -DCROW_ENABLE_COMPRESSION -lz ``` -------------------------------- ### Admin Area Guard Middleware Example Source: https://crowcpp.org/master/guides/middleware A middleware example that restricts access to admin routes based on the client's IP address. It checks the remote IP in `before_handle` and ends the response if it doesn't match the expected ADMIN_IP. ```cpp struct AdminAreaGuard { struct context {}; void before_handle(crow::request& req, crow::response& res, context& ctx) { if (req.remote_ip_address != ADMIN_IP) { res.code = 403; res.end(); } } void after_handle(crow::request& req, crow::response& res, context& ctx) {} }; ``` -------------------------------- ### SSLAdaptor::address Source: https://crowcpp.org/master/reference/structcrow_1_1_s_s_l_adaptor.html Gets the local address of the connection. ```APIDOC ## SSLAdaptor::address ### Description Retrieves the local IP address of the socket connection. ### Signature `std::string address() const` ### Returns A string representing the local IP address. ``` -------------------------------- ### Explicitly Serve Static Files Source: https://crowcpp.org/master/guides/static Examples of serving static files using Crow's macro and function-based APIs. The file paths are relative to the working directory. ```cpp auto app = crow::SimpleApp(); // or crow::App() // by Macro CROW_STATIC_FILE(app, "/" , "home.html"); CROW_STATIC_FILE(app, "/home.html" , "home.html"); // by Function app.static_file("/favicon.ico", "images/home.png"); app.static_file("/style.css", "style.css"); ``` -------------------------------- ### get_tick_length() Source: https://crowcpp.org/master/reference/functions_func.html Gets the tick length of a task timer. ```APIDOC ## get_tick_length() ### Description Retrieves the tick length (interval) of the task timer. ### Method Not specified (likely a member function) ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response Returns crow::detail::task_timer. ``` -------------------------------- ### get_default_timeout() Source: https://crowcpp.org/master/reference/functions_func.html Gets the default timeout for a task timer. ```APIDOC ## get_default_timeout() ### Description Retrieves the default timeout value for the task timer. ### Method Not specified (likely a member function) ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response Returns crow::detail::task_timer. ``` -------------------------------- ### port Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Sets or gets the port number for the server. ```APIDOC ## port ### Description Sets or gets the port number for the server. ### Method [Method details not specified in source] ### Endpoint [Endpoint details not specified in source] ### Parameters #### Path Parameters - **port** (std::uint16_t) - Optional - The port number to set. #### Query Parameters [No query parameters specified] #### Request Body [No request body specified] ### Request Example [No request example specified] ### Response #### Success Response (200) - **return value** (std::uint16_t) - The current port number if no argument is provided. #### Response Example [No response example specified] ``` -------------------------------- ### Start WebSocket Connection Source: https://crowcpp.org/master/reference/websocket_8h_source.html Initiates the WebSocket connection by sending the HTTP 101 Switching Protocols response. Sets up necessary headers and begins reading messages. ```cpp void start(std::string&& hello) { static const std::string header = "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Accept: "; write_buffers_.emplace_back(header); write_buffers_.emplace_back(std::move(hello)); write_buffers_.emplace_back(crlf); if (!subprotocol_.empty()) { write_buffers_.emplace_back("Sec-WebSocket-Protocol: "); write_buffers_.emplace_back(subprotocol_); write_buffers_.emplace_back(crlf); } write_buffers_.emplace_back(crlf); do_write(); if (open_handler_) open_handler_(*this); do_read(); } ``` -------------------------------- ### exception_handler Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Sets or gets the exception handler function. ```APIDOC ## exception_handler ### Description Sets or gets the exception handler function. ### Method [Method details not specified in source] ### Endpoint [Endpoint details not specified in source] ### Parameters #### Path Parameters - **f** (Func &&) - Optional - The exception handler function. #### Query Parameters [No query parameters specified] #### Request Body [No request body specified] ### Request Example [No request example specified] ### Response #### Success Response (200) [No success response specified] #### Response Example [No response example specified] ``` -------------------------------- ### Server Constructor Source: https://crowcpp.org/master/reference/http__server_8h_source.html Initializes the Crow HTTP server with specified parameters. It handles the setup of the acceptor, binding to the endpoint, and listening for incoming connections. Startup failures are logged. ```APIDOC ## Server Constructor ### Description Initializes the Crow HTTP server with specified parameters. It handles the setup of the acceptor, binding to the endpoint, and listening for incoming connections. Startup failures are logged. ### Parameters - **handler** (*Handler*): A pointer to the handler object. - **endpoint** (*Acceptor::endpoint*): The network endpoint to bind to. - **server_name** (std::string, optional): The name of the server. Defaults to "Crow/" + VERSION. - **middlewares** (std::tuple*, optional): A pointer to a tuple of middlewares. - **concurrency** (unsigned int, optional): The number of concurrent worker threads. Defaults to 1. - **timeout** (uint8_t, optional): The timeout value in seconds. Defaults to 5. - **adaptor_ctx** (Adaptor::context*, optional): A pointer to the adaptor context. ``` -------------------------------- ### concurrency Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Sets or gets the number of concurrent threads. ```APIDOC ## concurrency ### Description Sets or gets the number of concurrent threads. ### Method [Method details not specified in source] ### Endpoint [Endpoint details not specified in source] ### Parameters #### Path Parameters - **concurrency** (unsigned int) - Optional - The number of concurrent threads. #### Query Parameters [No query parameters specified] #### Request Body [No request body specified] ### Request Example [No request example specified] ### Response #### Success Response (200) - **return value** (unsigned int) - The current concurrency setting if no argument is provided. #### Response Example [No response example specified] ``` -------------------------------- ### Parse HTTP Version Start Source: https://crowcpp.org/master/reference/http__parser__merged_8h_source.html Handles the initial 'H' character when parsing the HTTP version string. Transitions to the next state for 'T'. ```cpp case s_req_http_start: switch (ch) { case ' ': break; case 'H': parser->state = s_req_http_H; break; case 'I': if (parser->method == (unsigned)HTTPMethod::Source) { parser->state = s_req_http_I; break; } /* fall through */ default: CROW_SET_ERRNO(CHPE_INVALID_CONSTANT); goto error; } break; ``` -------------------------------- ### bindaddr Source: https://crowcpp.org/master/reference/classcrow_1_1_crow-members.html Sets or gets the bind address for the server. ```APIDOC ## bindaddr ### Description Sets or gets the bind address for the server. ### Method [Method details not specified in source] ### Endpoint [Endpoint details not specified in source] ### Parameters #### Path Parameters - **bindaddr** (std::string) - Optional - The address to bind to. #### Query Parameters [No query parameters specified] #### Request Body [No request body specified] ### Request Example [No request example specified] ### Response #### Success Response (200) - **return value** (std::string) - The current bind address if no argument is provided. #### Response Example [No response example specified] ``` -------------------------------- ### Configure SSL Context Source: https://crowcpp.org/master/reference/app_8h_source.html Allows direct configuration of the SSL context by moving an existing `asio::ssl::context` object. This provides maximum flexibility for advanced SSL setups. ```cpp ssl_used_ = true; ssl_context_ = std::move(ctx); return *this; ``` -------------------------------- ### wvalue Constructors Source: https://crowcpp.org/master/reference/json_8h_source.html Demonstrates the various ways to construct a wvalue object, including copy and move constructors, and initialization from different data types. ```APIDOC ## wvalue(const wvalue& r) ### Description Copy constructor for creating a new wvalue object from an existing one. ## wvalue(wvalue&& r) ### Description Move constructor for efficiently transferring ownership of resources from a temporary wvalue object. ``` -------------------------------- ### Configure and Run Crow App Source: https://crowcpp.org/master/guides/app Configure the app's bind address, port, SSL files, and multithreading settings, then run it. The methods can be chained for concise configuration. ```cpp app.bindaddr("192.168.1.2").port(443).ssl_file("certfile.crt","keyfile.key").multithreaded().run(); ``` ```cpp app.bindaddr("192.168.1.2") .port(443) .ssl_file("certfile.crt","keyfile.key") .multithreaded() .run(); ``` -------------------------------- ### get() Source: https://crowcpp.org/master/reference/structcrow_1_1session_1_1multi__value.html Retrieves the value from the multi_value, with a fallback if the type does not match. ```APIDOC ## get> (const T &fallback) ### Description Retrieves the value from the multi_value. If the stored value is not of type T, the fallback value is returned. ### Parameters #### Path Parameters - **fallback** (const T &) - The value to return if the stored type does not match T. ### Method `RT get(const T &fallback)` ``` -------------------------------- ### Server Start Logging Source: https://crowcpp.org/master/reference/http__server_8h_source.html Logs information about the server's running status, including its URL and the number of threads used. Provides a hint to hide info logs. ```cpp CROW_LOG_INFO << server_name_ << " server is running at " << acceptor_.url_display(handler_->ssl_used()) << " using " << concurrency_ << " threads"; CROW_LOG_INFO << "Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs."; ``` -------------------------------- ### local_socket_path (getter) Source: https://crowcpp.org/master/reference/app_8h_source.html Gets the Unix domain socket path. ```APIDOC ## local_socket_path ### Description Get the unix domain socket path. ### Signature ```cpp std::string local_socket_path() ``` ### Returns * `std::string`: The Unix domain socket path. ``` -------------------------------- ### port (getter) Source: https://crowcpp.org/master/reference/app_8h_source.html Gets the port that Crow will handle requests on. ```APIDOC ## port ### Description Get the port that Crow will handle requests on. ### Signature ```cpp std::uint16_t port() const ``` ### Returns * `std::uint16_t`: The port number. ``` -------------------------------- ### loglevel() Source: https://crowcpp.org/master/reference/functions_l.html Gets the current log level of the Crow framework. ```APIDOC ## loglevel() ### Description Returns the current log level configured for the Crow framework. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters None ### Request Example None ### Response #### Success Response (N/A) - **Return Value** (log level type) - The current log level. ### Response Example None ``` -------------------------------- ### Setup Session Middleware with FileStore Source: https://crowcpp.org/master/guides/included-middleware Configure the Session middleware using `crow::FileStore` to manage client session data. Ensure `CookieParser` is listed before `Session`. The `FileStore` path and default cookie expiration can be customized. ```cpp using Session = crow::SessionMiddleware; crow::App app{Session{ crow::FileStore{"/tmp/sessiondata"} }}; ``` -------------------------------- ### Initialize and Run Worker Threads Source: https://crowcpp.org/master/reference/http__server_8h_source.html Initializes a task timer and then enters a loop to run the io_context. Handles exceptions during execution and breaks when no more work is available. ```cpp // initializing task timers detail::task_timer task_timer(*io_context_pool_[i]); task_timer.set_default_timeout(timeout_); task_timer_pool_[i] = &task_timer; task_queue_length_pool_[i] = 0; init_count++; while (1) { try { if (io_context_pool_[i]->run() == 0) { // when io_service.run returns 0, there are no more works to do. break; } } catch (std::exception& e) { CROW_LOG_ERROR << "Worker Crash: An uncaught exception occurred: " << e.what(); } } ``` -------------------------------- ### Getting the underlying value Source: https://crowcpp.org/master/reference/classcrow_1_1json_1_1wvalue-members.html Retrieves the underlying value of the wvalue. ```APIDOC ## t() const ### Description Retrieves the underlying value of the wvalue. The exact type depends on the stored JSON type. ### Method t ``` -------------------------------- ### Blueprint and Static Directory Application Source: https://crowcpp.org/master/reference/app_8h_source.html Applies registered blueprints and sets up static directory serving. ```APIDOC ## add_blueprint() ### Description Applies all registered blueprints. If any blueprint has an empty static directory, it and its sub-blueprints will be ignored with an error log. ### Method `add_blueprint` ## add_static_dir() ### Description Adds routes for serving static files from the default static directory (`CROW_STATIC_DIRECTORY`). This function is skipped if static routes have already been added. ### Method `add_static_dir` ``` -------------------------------- ### userdata Source: https://crowcpp.org/master/reference/classcrow_1_1websocket_1_1_connection-members.html Sets or gets user-defined data associated with the connection. ```APIDOC ## userdata ### Description Sets or gets user-defined data associated with the connection. ### Method inline ### Parameters - **u** (void *) - The user data to set. ### Return Value void (when setting) void * (when getting) ``` -------------------------------- ### CMake Build Options for Crow Source: https://crowcpp.org/master/getting_started/setup/macos Example CMake build commands with optional flags to enable features like HTTP Compression or SSL support. ```bash cmake .. -DCROW_ENABLE_COMPRESSION=ON ``` ```bash cmake .. -DCROW_ENABLE_SSL=ON ``` ```bash cmake .. -DCROW_AMALGAMATE ``` -------------------------------- ### Run Server Asynchronously Source: https://crowcpp.org/master/reference/functions_func.html Starts the Crow server in a non-blocking manner. ```APIDOC ## run_async() ### Description Starts the Crow web server in a separate thread, allowing the main thread to continue execution. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None (Server runs in the background). ``` -------------------------------- ### ssl_file(const std::string& crt_filename, const std::string& key_filename) Source: https://crowcpp.org/master/reference/app_8h_source.html Configures SSL using certificate and key files. This method is available only when CROW_ENABLE_SSL is defined. ```APIDOC ## ssl_file(const std::string& crt_filename, const std::string& key_filename) ### Description Configures SSL using certificate and key files. This method is available only when CROW_ENABLE_SSL is defined. ### Method `self_t& ssl_file(const std::string& crt_filename, const std::string& key_filename)` ### Endpoint N/A (Method call) ### Parameters - **crt_filename** (`const std::string&`) - Path to the certificate file. - **key_filename** (`const std::string&`) - Path to the private key file. ### Request Example ```cpp app.ssl_file("cert.pem", "key.pem"); ``` ### Response `self_t&`: Returns a reference to the application object for chaining. ``` -------------------------------- ### crow::Server::Server Constructor Source: https://crowcpp.org/master/reference/classcrow_1_1_server-members.html Constructs a new Server instance, initializing it with a handler, endpoint, and optional configurations. ```APIDOC ## Server() ### Description Constructor for the crow::Server class. Initializes the server with necessary components like handler, endpoint, and optional middlewares, concurrency settings, timeout, and adaptor context. ### Method `Server(Handler *handler, typename Acceptor::endpoint endpoint, std::string server_name=std::string("Crow/" + VERSION), std::tuple< Middlewares... > *middlewares=nullptr, unsigned int concurrency=1, uint8_t timeout=5, typename Adaptor::context *adaptor_ctx=nullptr)` ### Parameters * **handler** (Handler *) - A pointer to the request handler. * **endpoint** (typename Acceptor::endpoint) - The network endpoint the server will bind to. * **server_name** (std::string, optional) - The name of the server. Defaults to "Crow/" + VERSION. * **middlewares** (std::tuple< Middlewares... > *, optional) - A tuple of middlewares to be used by the server. * **concurrency** (unsigned int, optional) - The number of concurrent threads to use. Defaults to 1. * **timeout** (uint8_t, optional) - The timeout value in seconds. Defaults to 5. * **adaptor_ctx** (typename Adaptor::context *, optional) - Context for the network adaptor. ``` -------------------------------- ### SSLAdaptor Constructor Source: https://crowcpp.org/master/reference/socket__adaptors_8h_source.html Initializes an SSLAdaptor with an io_context and an SSL context. ```cpp SSLAdaptor(asio::io_context& io_context, context* ctx) : ssl_socket_(new ssl_socket_t(io_context, *ctx)) {} ``` -------------------------------- ### crow::Crow::concurrency Source: https://crowcpp.org/master/reference/app_8h_source.html Gets the number of threads the server is using. ```APIDOC ## concurrency ### Description Get the number of threads that server is using. ### Method Signature `std::uint16_t concurrency() const` ```