{"id":13424619,"url":"https://github.com/kenba/via-httplib","last_synced_at":"2025-03-15T18:35:33.781Z","repository":{"id":6434875,"uuid":"7673595","full_name":"kenba/via-httplib","owner":"kenba","description":"A library for embedding an HTTP or HTTPS server in C++ applications.","archived":false,"fork":false,"pushed_at":"2024-01-08T18:36:39.000Z","size":2622,"stargazers_count":45,"open_issues_count":3,"forks_count":15,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-10-26T23:55:33.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_1_0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-01-17T20:24:18.000Z","updated_at":"2024-08-18T04:44:52.000Z","dependencies_parsed_at":"2024-01-28T09:53:49.406Z","dependency_job_id":null,"html_url":"https://github.com/kenba/via-httplib","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenba%2Fvia-httplib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenba%2Fvia-httplib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenba%2Fvia-httplib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenba%2Fvia-httplib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenba","download_url":"https://codeload.github.com/kenba/via-httplib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243775902,"owners_count":20346283,"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","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-07-31T00:00:57.078Z","updated_at":"2025-03-15T18:35:28.759Z","avatar_url":"https://github.com/kenba.png","language":"C++","funding_links":[],"categories":["Rest protocol"],"sub_categories":[],"readme":"# via-httplib: A C++ HTTP Library\n\n[![C/C++ CI](https://github.com/kenba/via-httplib/workflows/C/C++%20CI/badge.svg)](https://github.com/kenba/via-httplib/actions)\n[![License](https://img.shields.io/badge/License-Boost%201.0-blue)](https://opensource.org/licenses/BSL-1.0)\n\nA header-only library for embedding **HTTP** or **HTTPS**, **IPV6** and **IPV4** servers in C++ applications.\n\n`via-httplib` is an asynchronous communications library built upon `asio` (either\n[boost](https://www.boost.org/doc/libs/1_76_0/doc/html/boost_asio.html) or\n[standalone](http://think-async.com/)) to enable simple, secure and efficient\nHTTP/HTTPS servers to be built that comply with\n[rfc7230](https://tools.ietf.org/html/rfc7230) wherever possible.\n\n## Requirements\n\n+ A C++17 compliant compiler. This version requires a complier that supports `string_view`.  \nIt's been tested with `MSVC 2022`, `GCC 12.3.0` and `MinGw 11.2.0`.  \nC++11 versions are available in tags `1.6.0` and lower.  \n\n+ The `asio` C++ library, either [standalone asio](http://think-async.com/) or [boost asio](http://www.boost.org/).  \n\n+ For: multithreading, authentication and/or the request router, the relevant [boost](http://www.boost.org/) libraries are required.  \n\n+ For HTTPS: the `OpenSSL` library, see [openssl](http://www.openssl.org/).  \n\n+ For C++ code documentation: [Doxygen](https://doxygen.nl/)\n\n## Getting Started\n\nDownload the latest tagged version of `via-httplib` from\n[Github](https://github.com/kenba/via-httplib)\nand follow the instructions here: [Make](docs/MAKE.md).  \n\n`via-http` lib depends on the `standalone asio` or `boost` libraries.  \nIf `boost` is not installed on your machine then download the latest package from\n[boost](http://www.boost.org/) and follow the instructions here:\n[boost getting started](http://www.boost.org/doc/libs/1_76_0/more/getting_started/index.html).\nOtherwise `standalone asio` can be downloaded from: [asio](http://think-async.com/).\n\nIf you require an **HTTPS** server or client then you must also install the\n[OpenSSL](https://www.openssl.org/) library.  \nPlease note that a plain **HTTP** server does **not** require `OpenSLL`.\n\nThe [Server User Guide](docs/Server.md) explains how to use the library to create HTTP servers and\nthe [Client User Guide](docs/Client.md) explains how to use the library to create HTTP clients.\n\nAn example https server [docker](https://www.docker.com/) image can be built using\nthe following commands from this directory:\n\n```shell\ndocker build . -t via-http-server:0.1\n```\n\n## Example HTTP Server\n\nThe following code implements an HTTP server that responds to GET requests to the\n`/hello` and `/hello/:name` endpoints:\n\n```C++\n#include \"via/comms/tcp_adaptor.hpp\"\n#include \"via/http_server.hpp\"\n#include \"via/http/request_router.hpp\"\n#include \u003ciostream\u003e\n\n/// Define an HTTP server using std::string to store message bodies\ntypedef via::http_server\u003cvia::comms::tcp_adaptor, std::string\u003e http_server_type;\ntypedef http_server_type::http_connection_type http_connection;\ntypedef http_server_type::http_request http_request;\n\nnamespace\n{\n  using namespace via::http;\n\n  /// /hello request handler\n  tx_response get_hello_handler(http_request const\u0026, //request,\n                                Parameters const\u0026, //parameters,\n                                std::string const\u0026, // data,\n                                std::string \u0026response_body)\n  {\n    response_body += \"Hello, whoever you are?!\";\n    return tx_response(response_status::code::OK);\n  }\n\n  /// /hello/:name request handler\n  tx_response get_hello_name_handler(http_request const\u0026, //request,\n                                     Parameters const\u0026 parameters,\n                                     std::string const\u0026, // data,\n                                     std::string \u0026response_body)\n  {\n    response_body += \"Hello, \";\n    auto iter(parameters.find(\"name\"));\n    if (iter != parameters.end())\n      response_body += iter-\u003esecond;\n\n    return tx_response(response_status::code::OK);\n  }\n}\n\nint main(int /* argc */, char *argv[])\n{\n  std::string app_name(argv[0]);\n  unsigned short port_number(via::comms::tcp_adaptor::DEFAULT_HTTP_PORT);\n  std::cout \u003c\u003c app_name \u003c\u003c \": \" \u003c\u003c port_number \u003c\u003c std::endl;\n\n  try\n  {\n    // The asio io_context.\n    boost::asio::io_context io_context;\n\n    // Create the HTTP server\n    http_server_type http_server(io_context);\n\n    // Attach the request method handlers\n    http_server.request_router().add_method(\"GET\", \"/hello\", get_hello_handler);\n    http_server.request_router().add_method(request_method::GET, \"/hello/:name\",\n                                            get_hello_name_handler);\n\n    // Accept connections (both IPV4 and IPV6) on the default port (80)\n    boost::system::error_code error(http_server.accept_connections());\n    if (error)\n    {\n      std::cerr \u003c\u003c \"Error: \"  \u003c\u003c error.message() \u003c\u003c std::endl;\n      return 1;\n    }\n\n    // Start the server\n    io_context.run();\n  }\n  catch (std::exception\u0026 e)\n  {\n    std::cerr \u003c\u003c \"Exception:\"  \u003c\u003c e.what() \u003c\u003c std::endl;\n    return 1;\n  }\n\n  return 0;\n}\n```\n\n## Documentation\n\n| Document | Description |\n|----------|-------------|\n| [Build Guide](docs/MAKE.md) | How to build the library. |\n| [Server User Guide](docs/Server.md) | How to use the library to create HTTP servers. |\n| [Client User Guide](docs/Client.md) | How to use the library to create HTTP clients. |\n| [Security Guide](docs/Server_Security.md) | HTTP Server security considerations. |\n| [Design](docs/Design_Top.md) | The library design. |\n| [examples/server](examples/server) | Example HTTP \u0026 HTTPS servers. |\n| [examples/client](examples/client) | Example HTTP \u0026 HTTPS clients. |\n\n## Directory Structure\n\n| Directory            | Contents                                                                 |\n|----------------------|--------------------------------------------------------------------------|\n| [via](include/via)           | The `via-httplib` API classes: [http_server](include/via/http_server.hpp), [http_connection](include/via/http_connection.hpp) and [http_client](include/via/http_client.hpp). |\n| [examples/server](examples/server) | Example HTTP \u0026 HTTPS servers.                              |\n| [examples/client](examples/client) | Example HTTP \u0026 HTTPS clients.                              |\n| [tests](tests)       | Unit tests for the HTTP parsers and encoders.                            |\n| [docs](docs)         | The User Guides and design documents.                                    |\n| `docs/html`          | [Doxygen](https://doxygen.nl/) output directory. Created by running `doxygen Doxyfile` in the [docs](docs) directory. |\n\n## License\n\nLicensed under the Boost License, Version 1.0, as per Boost.  \nYou may obtain a copy of the License at: \u003chttps://www.boost.org/LICENSE_1_0.txt\u003e\n\n## Acknowledgements\n\nThanks to:\n\n+ **Neil Tisdale** for encouraging and inspiring me to create the library\n+ **Louis Nayegon** for helping to develop it and recommending GitHub  \n+ **Adam Leggett** for helping to identify and fix security, efficiency and CMake issues\n+ **Christopher Kohlhoff** for the `asio` library, without which, this library wouldn't exist.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenba%2Fvia-httplib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenba%2Fvia-httplib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenba%2Fvia-httplib/lists"}