{"id":16162559,"url":"https://github.com/sunsided/http-grpc-cohosting","last_synced_at":"2026-04-28T13:38:18.475Z","repository":{"id":205370918,"uuid":"714080782","full_name":"sunsided/http-grpc-cohosting","owner":"sunsided","description":"Hosting Axum HTTP and Tonic gRPC on the same Hyper server","archived":false,"fork":false,"pushed_at":"2024-04-11T14:43:22.000Z","size":107,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T12:21:55.104Z","etag":null,"topics":["axum","grpc","http2","hyper","rust","tonic","unix-domain-sockets"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/sunsided.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}},"created_at":"2023-11-03T21:53:03.000Z","updated_at":"2024-04-19T21:24:02.366Z","dependencies_parsed_at":"2024-04-11T15:46:22.994Z","dependency_job_id":"b351777d-6a16-488d-a426-6f152924070f","html_url":"https://github.com/sunsided/http-grpc-cohosting","commit_stats":null,"previous_names":["sunsided/http-grpc-cohosting"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fhttp-grpc-cohosting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fhttp-grpc-cohosting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fhttp-grpc-cohosting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fhttp-grpc-cohosting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunsided","download_url":"https://codeload.github.com/sunsided/http-grpc-cohosting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247589835,"owners_count":20963022,"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":["axum","grpc","http2","hyper","rust","tonic","unix-domain-sockets"],"created_at":"2024-10-10T02:30:46.654Z","updated_at":"2026-04-28T13:38:18.431Z","avatar_url":"https://github.com/sunsided.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tonic gRPC and Axum HTTP/1.1+2 co-hosting in Rust\n\nAn attempt at hosting HTTP/1.1, HTTP/2 and gRPC on the same port(s).\n\nMultiple Hyper servers are spawned on different endpoints to showcase the use of binding to different IP addresses\nand ports while reusing the same server components. A Hyper service is used to switch the incoming traffic based on the\n`content-type` header and if `application/grpc` is detected, traffic is forwarded to the Tonic server; all other\ncases forward to Axum. This allows for transparent use of HTTP/1.1 and HTTP/2 (prior knowledge), as well\nas ALPN on the TLS-enabled ports. On Unixoids, Unix Domain Sockets are supported as well. \n\nThis project uses:\n\n- [Hyper] as the server for HTTP/1 and HTTP/2 support.\n  - [tls-listener] with [tokio-rustls] is used to provide TLS with `h2` and `http/1.1` ALPN support.\n- [Axum] as the HTTP server.\n- [Tonic] as the gRPC server.\n\n[Hyper]: https://github.com/hyperium/hyper\n[Axum]: https://github.com/tokio-rs/axum\n[Tonic]: https://github.com/hyperium/tonic\n[tls-listener]: https://github.com/tmccombs/tls-listener\n[tokio-rustls]: https://github.com/rustls/tokio-rustls\n\n## Curl\n\n### non-TLS\n\n```shell\ncurl -v http://127.0.0.1:36849/\ncurl -v http://127.1.0.1:36849/\ncurl --http2-prior-knowledge --insecure -vv http://127.0.0.1:36849/\n```\n\n### Unix Domain Sockets\n\n```shell\ncurl -v --unix-socket /tmp/cohosting.sock http://localhost:36849/\n```\n\n### TLS with ALPN\n\n```shell\ncurl --insecure -v https://127.0.0.1:36850/\ncurl --http1.1 --insecure -vv https://127.0.0.1:36850/\ncurl --http2 --insecure -vv https://127.0.0.1:36850/\n```\n\n## nghttp (HTTP/2)\n\n```shell\nnghttp -v http://127.0.0.1:36849\nnghttp -y -v https://127.0.0.1:36850\n```\n\n## gRPC testing\n\nUse gRPC reflection to introspect the service: \n\n```shell\ngrpcurl --plaintext --use-reflection 127.0.0.1:36849 list\ngrpcurl --insecure --use-reflection 127.0.0.1:36850 list\n```\n\nSend a test request:\n\n```shell\ngrpcurl --plaintext --use-reflection -d '{ \"message\": \"World\" }' 127.0.0.1:36849 example.YourService/YourMethod\ngrpcurl --insecure --use-reflection -d '{ \"message\": \"World\" }' 127.0.0.1:36850 example.YourService/YourMethod\n```\n\n### Unix Domain Sockets\n\nFor UDS to work with gRPC, the `:authority` header needs to be sent. In `grpcurl`, the `--authority=xyz` flag\nis used for that:\n\n```shell\ngrpcurl --unix --plaintext --use-reflection --authority localhost -d '{ \"message\": \"World\" }' /tmp/cohosting.sock example.YourService/YourMethod\n```\n\n## Recommended reads\n\nThe _Combining Axum, Hyper, Tonic, and Tower for hybrid web/gRPC apps_ series:\n\n- [Part 1: Overview of Tower](https://www.fpcomplete.com/blog/axum-hyper-tonic-tower-part1/)\n- [Part 2: Understanding Hyper, and first experiences with Axum](https://www.fpcomplete.com/blog/axum-hyper-tonic-tower-part2/)\n- [Part 3: Demonstration of Tonic for a gRPC client/server](https://www.fpcomplete.com/blog/axum-hyper-tonic-tower-part3/)\n- [Part 4: How to combine Axum and Tonic services into a single service](https://www.fpcomplete.com/blog/axum-hyper-tonic-tower-part4/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fhttp-grpc-cohosting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunsided%2Fhttp-grpc-cohosting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fhttp-grpc-cohosting/lists"}