{"id":23236792,"url":"https://github.com/pratikpc/beast-web-server","last_synced_at":"2025-10-05T22:52:14.592Z","repository":{"id":125288194,"uuid":"328297281","full_name":"pratikpc/Beast-Web-Server","owner":"pratikpc","description":"Simple Boost Beast based Web server library","archived":false,"fork":false,"pushed_at":"2021-01-10T04:21:36.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T21:17:27.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pratikpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-10T03:44:17.000Z","updated_at":"2021-01-18T01:50:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"b7262990-e787-4954-90e7-1f3210e70b49","html_url":"https://github.com/pratikpc/Beast-Web-Server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pratikpc/Beast-Web-Server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratikpc%2FBeast-Web-Server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratikpc%2FBeast-Web-Server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratikpc%2FBeast-Web-Server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratikpc%2FBeast-Web-Server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pratikpc","download_url":"https://codeload.github.com/pratikpc/Beast-Web-Server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pratikpc%2FBeast-Web-Server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278532356,"owners_count":26002346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-19T04:12:45.116Z","updated_at":"2025-10-05T22:52:14.534Z","avatar_url":"https://github.com/pratikpc.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Beast-Web-Server\n\n### Why Coroutines?\n\nCallback hell is bad and gives me headaches.    \nOkay callbacks are not bad but its easier to write bad code which\n1. Involves tons of magic and weird recursion\n2. Needs one to write 10 lines about what the code does\n3. Needs one to update those 10 lines once the code changes (yeah right? Who does that? Hello?)\n\nCoroutine codes look a lot more linear instead, sometimes end up being shorter and more easier to understand.\n\nCompare\n[Full Sample here](https://www.boost.org/doc/libs/develop/doc/html/boost_asio/example/cpp17/coroutines_ts/echo_server.cpp)\n```cpp\n    char data[1024];\n    for (;;)\n    {\n      std::size_t n = co_await socket.async_read_some(boost::asio::buffer(data), use_awaitable);\n      co_await async_write(socket, boost::asio::buffer(data, n), use_awaitable);\n    }\n```\n\nvs\n[Full Sample here](https://www.boost.org/doc/libs/develop/doc/html/boost_asio/example/cpp11/echo/async_tcp_echo_server.cpp)\n```cpp\n  void do_read()\n  {\n    socket_.async_read_some(boost::asio::buffer(data_, max_length),\n        [this, self](boost::system::error_code ec, std::size_t length)\n        {\n            do_write(length);\n        });\n  }\n\n  void do_write(std::size_t length)\n  {\n    boost::asio::async_write(socket_, boost::asio::buffer(data_, length),\n        [this, self](boost::system::error_code, std::size_t /*length*/)\n        {\n            do_read();\n        });\n  }\n```\n\n#### What does the above code do @pratikpc?    \nIt's a glorified echo server.        \nA bit less obvious from the second sample I presume.   \nIn an echo server, an individual sends a message say _Hello_ to the server and the server responds with _Hello_.\n\n### Simplified usage\n\n```cpp\n      PC::Lib::HTTPServer::ServerAPI api;\n      api.Get(std::regex(\"/\"),\n              [](PC::Lib::HTTPServer::Request\u003cstd::string\u003e\u0026\u0026 x,\n                 boost::asio::use_awaitable_t\u003c\u003e)\n                  -\u003e boost::asio::awaitable\u003cPC::Lib::HTTPServer::Response\u003cstd::string\u003e\u003e {\n                 std::this_thread::sleep_for(std::chrono::seconds(4));\n                 co_return PC::Lib::HTTPServer::Response\u003cstd::string\u003e{\n                     boost::beast::http::status::ok, \"Hi\"};\n              });\n      boost::asio::co_spawn(\n          io_context, api({boost::asio::ip::tcp::v4(), PORT}), boost::asio::detached);\n```\n\nFor a full sample, check [here](src/main.cxx)\n\n### Why?\n\nIt's a simple proof of concept and it was fun to write\n\n### References. I want to build my own\n\nRefer to docs on Coroutines.\n1. [Refer to Boost ASIO Docs](https://www.boost.org/doc/libs/develop/doc/html/boost_asio/example/cpp17/coroutines_ts/refactored_echo_server.cpp)\n2. [Refer to Boost Beast Boost Coroutine docs](https://www.boost.org/doc/libs/develop/libs/beast/example/http/client/coro/http_client_coro.cpp)\n3. A bit of Boost Beast code might look a bit anti-pattern when it comes to C++ Coroutines so remember to focus on Boost.ASIO code well.\n4. @MattPD [maintains a gist of coro related articles] (https://gist.github.com/MattPD/9b55db49537a90545a90447392ad3aeb#file-cpp-std-coroutines-draft-md)\n\n### Dependencies\n\n1. CMake\n2. Compiler that supports C++ Coroutines.\n3. Dependency installation will be handled via VCPKG\n\n### Use with my own CMake based project\n\n```cmake\ntarget_link_libraries(${PROJECT_NAME}\nPUBLIC\nlibs::Beast-Web\n)\n```\n\nFor a full sample check [here](src/CMakeLists.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratikpc%2Fbeast-web-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpratikpc%2Fbeast-web-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratikpc%2Fbeast-web-server/lists"}