{"id":19662717,"url":"https://github.com/brunexgeek/webster","last_synced_at":"2025-04-28T21:32:08.461Z","repository":{"id":43328363,"uuid":"129824125","full_name":"brunexgeek/webster","owner":"brunexgeek","description":"Small and standalone HTTP server/client API","archived":false,"fork":false,"pushed_at":"2024-01-03T01:48:39.000Z","size":355,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T11:12:54.026Z","etag":null,"topics":["c","cpp","http","http-client","http-server","networking","webster"],"latest_commit_sha":null,"homepage":"https://brunocosta.net.br/project/webster/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brunexgeek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-04-17T00:47:48.000Z","updated_at":"2024-07-06T21:31:37.000Z","dependencies_parsed_at":"2024-01-03T03:21:49.324Z","dependency_job_id":"b945f98d-4424-4525-9607-53ce5b3a0f33","html_url":"https://github.com/brunexgeek/webster","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunexgeek%2Fwebster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunexgeek%2Fwebster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunexgeek%2Fwebster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunexgeek%2Fwebster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brunexgeek","download_url":"https://codeload.github.com/brunexgeek/webster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251391264,"owners_count":21582138,"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":["c","cpp","http","http-client","http-server","networking","webster"],"created_at":"2024-11-11T16:12:11.033Z","updated_at":"2025-04-28T21:32:08.057Z","avatar_url":"https://github.com/brunexgeek.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webster  ![GitHub](https://img.shields.io/github/license/brunexgeek/webster) [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fbrunexgeek%2Fwebster%2Fbadge%3Fref%3Dmaster\u0026label=build\u0026logo=none)](https://actions-badge.atrox.dev/brunexgeek/webster/goto?ref=master)\n\nLightweight library to create HTTP servers and clients in C++11. It implements the [RFC-7230 - Message Syntax and Routing](https://tools.ietf.org/html/rfc7230) on top of POSIX socket API, however you can change the communication channel by specifying a custom network stack.\n\nWebster enables you to communicate with HTTP servers or implement your own HTTP server. It automatically parses requests and also simplify creating responses. The input/output body data is handled as a stream: to transmit data, you call write functions; to receive data, you call read functions. This enables you to handle large amounts of data using small buffers.\n\nTo use Webster you can link with `libwebster` static library or include the files ``webster.cc`` and ``webster.hh`` in your project. The file ``webster.cc`` is an amalgamation of the files in the ``source`` directory.\n\nThe repository also includes three programs in the ``examples`` directory:\n\n* ``client.cc``: simple client program that send a request and print the response;\n* ``echo.cc``: simple server program that echoes information about the request;\n* ``indexing.cc``: more elaborated server program that implements directory indexing. Works only in GNU/Linux for now.\n\n## Client implementation\n\nTo send a message to an HTTP server, just create an `HttpClient` object and start the communication:\n\n``` c++\n// create a listener using a function\nHttpListener listener(my_client_handler);\n// create the HTTP client\nHttpClient client;\nif (client.open(\"http://duckduckgo.com:80/\") == WBERR_OK)\n{\n    // use the listener to send a request to \"/\"\n    client.communicate(\"/\", listener);\n    client.close();\n}\n```\n\nIn the example above, the ``my_client_handler`` is the function which send the request and receive the response. That function looks like this:\n\n``` c++\nint my_client_handler( Message \u0026request, Message \u0026response )\n{\n    // send a HTTP request\n    request.header.fields[\"Connection\"] = \"close\";\n    request.header.fields.set(WBFI_CONTENT_LENGTH, 0);\n    request.finish();\n\n    // wait until the message body is ready to be read\n    response.ready();\n    // read response body as text\n    const char *ptr = nullptr;\n    while (response.read(\u0026ptr) == WBERR_OK)\n        std::cout \u003c\u003c ptr \u003c\u003c std::endl;\n\n    return WBERR_OK;\n}\n```\n\nYou can also implement a listener by specializing the class ``HttpListener`` with a new implementation for ``operator()``. This way you can have a statefull listener.\n\n``` c++\nstruct MyListener : public HttpListener\n{\n\tint operator()( Message \u0026request, Message \u0026response )\n\t{\n        ...\n    }\n};\n```\n\n## Server implementation\n\nThe server keeps listening for connections and handle each one of them. To start the server, do something like:\n\n``` c++\nHttpServer server;\nif (server.start(\"http://localhost:7000\") == WBERR_OK)\n{\n    HttpListener listener(my_server_handler);\n    while (is_running)\n    {\n        HttpClient *remote = nullptr;\n        // wait for connections (uses `read_timeout`from `Parameters` class)\n        int result = server.accept(\u0026remote);\n        if (result == WBERR_OK)\n        {\n            // keep processing requests until some error occurs\n            while ((result = remote-\u003ecommunicate(listener)) == WBERR_OK);\n            // close the client (optional, closed by destructor) and destroy the object\n            remote-\u003eclose();\n            delete remote;\n        }\n        else\n        // `HttpServer::accept` will return `WBERR_TIMEOUT` if there were no connections\n        if (result != WBERR_TIMEOUT)\n            break;\n    }\n    server.stop();\n}\n```\n\nIn the example above, the ``my_server_handler`` is the function which receive the request and send the response to the client. This listener have the same signature of the client listener, however the request must be read (not written). For more details in the server implementation, see the files ``examples/echo.cc`` and ``examples/indexing.cc``.\n\n## Limitations\n\n* You cannot have multiple header fields with the same name ([RFC-7230 3.2.2 Field order](https://tools.ietf.org/html/rfc7230#section-3.2.2))\n* The library do not handle header fields according to [RFC-7231 - Semantics and Content](https://tools.ietf.org/html/rfc7231).\n* Support for SSL/TLS communication is not provided natively. You need to specialize the ``Network`` class using a 3rd-party library (e.g. [mbedTLS](https://tls.mbed.org)).\n## Roadmap\n\n* Documentation\n* Specialize ``Network`` for HTTPS using [mbedTLS](https://tls.mbed.org)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunexgeek%2Fwebster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunexgeek%2Fwebster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunexgeek%2Fwebster/lists"}