{"id":47609428,"url":"https://github.com/bytecodealliance/sample-wasi-http-cpp","last_synced_at":"2026-04-01T19:55:28.988Z","repository":{"id":326134285,"uuid":"1098563770","full_name":"bytecodealliance/sample-wasi-http-cpp","owner":"bytecodealliance","description":"Sample WASI HTTP Server implemented with C++ and `wit-bindgen cpp`","archived":false,"fork":false,"pushed_at":"2025-11-25T19:57:33.000Z","size":109,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-31T00:38:36.510Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytecodealliance.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-17T21:21:39.000Z","updated_at":"2025-11-25T20:40:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bytecodealliance/sample-wasi-http-cpp","commit_stats":null,"previous_names":["bytecodealliance/sample-wasi-http-cpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bytecodealliance/sample-wasi-http-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fsample-wasi-http-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fsample-wasi-http-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fsample-wasi-http-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fsample-wasi-http-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytecodealliance","download_url":"https://codeload.github.com/bytecodealliance/sample-wasi-http-cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fsample-wasi-http-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291307,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-04-01T19:55:27.288Z","updated_at":"2026-04-01T19:55:28.954Z","avatar_url":"https://github.com/bytecodealliance.png","language":"C++","readme":"# C++ HTTP Server WebAssembly Component\n\nA simple HTTP server built using C++ and WebAssembly Components with wasi:http.\n\n## Building\n\n### Prerequisites\n\n- WASI SDK 28.0 (wasm32-wasip2)\n- wit-bindgen 0.48.1+\n- wkg CLI\n\n### Quick Start with Makefile\n\nThe easiest way to build is using the provided Makefile:\n\n```bash\nmake\n```\n\nIf you have WASI SDK installed in a non-standard location:\n```bash\nmake WASI_SDK_PATH=/opt/wasi-sdk-28.0\n```\n\nOr set it as an environment variable:\n```bash\nexport WASI_SDK_PATH=/opt/wasi-sdk-28.0\nmake\n```\n\n### Manual Build Steps\n\nIf you prefer to build manually:\n\n1. **Fetch WIT dependencies**:\n   ```bash\n   wkg wit fetch\n   ```\n\n2. **Generate C++ bindings**:\n   ```bash\n   wit-bindgen cpp --out-dir bindings wit\n   ```\n\n3. **Compile the component**:\n   ```bash\n   wasm32-wasip2-clang++ \\\n     server.cpp \\\n     bindings/http_server.cpp \\\n     bindings/http_server_component_type.o \\\n     -I bindings \\\n     -I include \\\n     -Wall -Wextra -Werror -Wno-unused-parameter \\\n     -std=c++20 \\\n     -fno-exceptions \\\n     -mexec-model=reactor \\\n     -o http-server.wasm\n   ```\n\n## Running\n\nYou can run this component with any WASI HTTP host, such as wasmtime:\n\n```bash\nwasmtime serve -Scli http-server.wasm\n```\n\nThen test the endpoints:\n```bash\ncurl http://localhost:8080/\ncurl http://localhost:8080/hello\ncurl http://localhost:8080/echo/test\n```\n\n## Endpoints\n\n- `/` - Returns \"Hello, World!\"\n- `/hello` - Returns a greeting from the C++ component\n- `/echo/*` - Echoes back the request method and path\n- Other paths return 404\n\n## Implementation Notes\n\n- Uses wasi:http imported resources (IncomingRequest, ResponseOutparam, etc.)\n- Demonstrates proper use of `\u0026\u0026` move semantics for imported resources\n- Shows how to work with wit::string, std::expected, and std::variant\n- Properly handles resource lifetimes and cleanup\n\n## Generated with\n\nBuilt using wit-bindgen with the following fixes:\n1. Type alias resolution for imported resources\n2. Proper `\u0026\u0026` usage instead of `::Owned` for imported resources\n3. Move semantics for `std::expected` in optional emplacement\n\n## Dependencies\n\nThis project uses [tl::expected](https://github.com/TartanLlama/expected) (included in `include/tl/`) to provide `std::expected` compatibility for WASI SDK.\n\n### Why tl::expected?\n\nThe generated C++ bindings use `std::expected`, which is a C++23 feature. While WASI SDK 28.0 uses LLVM 21 (which has libc++ 21 with `std::expected` support), the WASI SDK distribution may not include the `\u003cexpected\u003e` header in its sysroot.\n\n**tl::expected** is a header-only, single-file implementation of `std::expected` that:\n- Works with C++11 and later (we use C++20)\n- Is API-compatible with the C++23 standard\n- Is released under CC0-1.0 license (public domain)\n- Requires no external dependencies\n\nThe `include/expected` header provides a compatibility layer that aliases `tl::expected` to `std::expected`, making the code work seamlessly with generated bindings.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytecodealliance%2Fsample-wasi-http-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytecodealliance%2Fsample-wasi-http-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytecodealliance%2Fsample-wasi-http-cpp/lists"}