{"id":13620257,"url":"https://github.com/Stiffstream/restinio","last_synced_at":"2025-04-14T19:31:35.551Z","repository":{"id":37431639,"uuid":"115361853","full_name":"Stiffstream/restinio","owner":"Stiffstream","description":"Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use","archived":false,"fork":false,"pushed_at":"2025-04-06T04:45:34.000Z","size":9123,"stargazers_count":1214,"open_issues_count":40,"forks_count":97,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-13T12:45:06.378Z","etag":null,"topics":["asio","cplusplus","cpp","http","http-server","https","library","linux","rest","tls-support","websockets","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stiffstream.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,"zenodo":null}},"created_at":"2017-12-25T20:34:27.000Z","updated_at":"2025-04-12T00:27:27.000Z","dependencies_parsed_at":"2024-11-08T06:32:39.459Z","dependency_job_id":"74ddfbf5-9c0e-43e1-957f-d9ced051bbe7","html_url":"https://github.com/Stiffstream/restinio","commit_stats":{"total_commits":1766,"total_committers":13,"mean_commits":"135.84615384615384","dds":0.5271800679501699,"last_synced_commit":"7994a15e64d28975fb05b5b483f9271bab38145b"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stiffstream%2Frestinio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stiffstream%2Frestinio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stiffstream%2Frestinio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stiffstream%2Frestinio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stiffstream","download_url":"https://codeload.github.com/Stiffstream/restinio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248945919,"owners_count":21187410,"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":["asio","cplusplus","cpp","http","http-server","https","library","linux","rest","tls-support","websockets","windows"],"created_at":"2024-08-01T21:00:53.851Z","updated_at":"2025-04-14T19:31:35.522Z","avatar_url":"https://github.com/Stiffstream.png","language":"C++","readme":"# What Is RESTinio?\n\nRESTinio is a C++17 library that gives you an embedded\nHTTP/Websocket server. It is based on standalone version of ASIO\nand targeted primarily for asynchronous processing of HTTP-requests.\nBoost::ASIO is also supported.\n\nRESTinio itself is a header-only library, but it depends on [nodejs/llhttp](https://github.com/nodejs/llhttp)\nthat is not header-only.\n\nCurrently *RESTinio* is in rather stable state and we think that since v.0.4.0\nit is ready for production use.\n\n# A Very Basic Example Of RESTinio\n\nConsider the task of writing a C++ application that must support some REST API,\nRESTinio represents our solution for that task.\n\nLets see how it feels like in the simplest case:\n\n```C++\n#include \u003crestinio/core.hpp\u003e\nint main()\n{\n    restinio::run(\n        restinio::on_this_thread()\n        .port(8080)\n        .address(\"localhost\")\n        .request_handler([](auto req) {\n            return req-\u003ecreate_response().set_body(\"Hello, World!\").done();\n        }));\n    return 0;\n}\n```\n\nServer runs on the main thread, and respond to all requests with hello-world\nmessage. Of course you've got an access to the structure of a given HTTP request,\nso you can apply a complex logic for handling requests.\n\n# Features\n\n* Async request handling. Cannot get the response data immediately? That's ok,\n  store request handle somewhere and/or pass it to another execution context\n  and get back to it when the data is ready.\n* HTTP pipelining. Works well with async request handling.\n  It might increase your server throughput dramatically.\n* Timeout control. RESTinio can take care of bad connection that are like: send\n  \"GET /\" and then just stuck.\n* Response builders. Need chunked-encoded body - then RESTinio has a special\n  response builder for you (obviously it is not the only builder).\n* ExpressJS-like request routing (see an example below).\n* An experimental typesafe request router that allows avoiding problems of ExpressJS-like router with help of static checks from C++ compiler.\n* A possibility to chain several request-handlers (somewhat similar to ExpressJS's middleware).\n* Working with query string parameters.\n* Several ready-to-use helpers for working with HTTP headers (for example, the support for HTTP headers related to file uploading).\n* Supports sending files and its parts (with sendfile on linux/unix and TransmitFile on windows).\n* Supports compression (deflate, gzip).\n* Supports TLS (HTTPS).\n* Basic websocket support. Simply restinio::websocket::basic::upgrade() the\n  request handle and start websocket session on a corresponding connection.\n* Can run on external asio::io_context. RESTinio is separated from execution\n  context.\n* Some tune options. One can set acceptor and socket options. When running\n  RESTinio on a pool of threads connections can be accepted in parallel.\n\n# Enhanced Example With Express Router\n\n```C++\n#include \u003crestinio/core.hpp\u003e\n\nusing namespace restinio;\n\ntemplate\u003ctypename T\u003e\nstd::ostream \u0026 operator\u003c\u003c(std::ostream \u0026 to, const optional_t\u003cT\u003e \u0026 v) {\n    if(v) to \u003c\u003c *v;\n    return to;\n}\n\nint main() {\n    // Create express router for our service.\n    auto router = std::make_unique\u003crouter::express_router_t\u003c\u003e\u003e();\n    router-\u003ehttp_get(\n            R\"(/data/meter/:meter_id(\\d+))\",\n            [](auto req, auto params) {\n                const auto qp = parse_query(req-\u003eheader().query());\n                return req-\u003ecreate_response()\n                        .set_body(\n                                fmt::format(\"meter_id={} (year={}/mon={}/day={})\",\n                                        cast_to\u003cint\u003e(params[\"meter_id\"]),\n                                        opt_value\u003cint\u003e(qp, \"year\"),\n                                        opt_value\u003cint\u003e(qp, \"mon\"),\n                                        opt_value\u003cint\u003e(qp, \"day\")))\n                        .done();\n            });\n\n    router-\u003enon_matched_request_handler(\n            [](auto req){\n                return req-\u003ecreate_response(restinio::status_not_found()).connection_close().done();\n            });\n\n    // Launching a server with custom traits.\n    struct my_server_traits : public default_single_thread_traits_t {\n        using request_handler_t = restinio::router::express_router_t\u003c\u003e;\n    };\n\n    restinio::run(\n            restinio::on_this_thread\u003cmy_server_traits\u003e()\n                    .address(\"localhost\")\n                    .request_handler(std::move(router)));\n\n    return 0;\n}\n```\n\n# License\n\nRESTinio is distributed under BSD-3-CLAUSE license.\n\n# How To Use It?\n\nThe full documentation for RESTinio can be found [here](https://stiffstream.com/en/docs/restinio/0.7/).\n\n# More\n\n* Issues and bugs:\n[Issue Tracker on GitHub](https://github.com/stiffstream/restinio/issues).\n* Discussion section [on GitHub](https://github.com/Stiffstream/restinio/discussions).\n* Discussion group: [restinio](https://groups.google.com/forum/#!forum/restinio).\n\n","funding_links":[],"categories":["Networking","内存分配","HTTP and the Web","C++"],"sub_categories":["网络"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStiffstream%2Frestinio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStiffstream%2Frestinio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStiffstream%2Frestinio/lists"}