-
Notifications
You must be signed in to change notification settings - Fork 15
add wstd-axum crate #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d585681 to
b6250e6
Compare
and add test for axum hello world. rather than need separate test-programs to build the bins, just build the examples. (I have no idea why I didn't do this in the first place.)
yoshuawuyts
approved these changes
Oct 23, 2025
Member
yoshuawuyts
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed this in a call today; looks great!
b6250e6 to
5bea217
Compare
5bea217 to
de99ea4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on #92
wstd-axumis a crate which makes it trivial to use theaxumcrate with a wasip2 http server.It contains
async fn serve(request: Request<Body>, service: impl tower_http::Service) -> Result<Response<Body>>which is the analog foraxum::serve, except in wasi-http terms instead of using a tokio socket.It also exports the
wstd_axum::http_serverproc macro which gets rid of the boilerplate used to convert awstd::http_serverto an axum server, and makes it so you never even see thewstd::httptypes in the resulting program.The integration itself is very thin, because
http_body::Bodyis doing 99% of the work!This is added as a separate crate, rather than an optional feature on wstd, because:
mainenough that it seems like a separate sort of thing. Idk, its vibes, I can go either way.In the future, I expect to refactor the macro to better support instance reuse, by initializing the
Serviceinto a OnceLock on first request and cloning it on subsequent, and making it possible to pre-initialize via component-init aka wizer.Weather example
To show Axum working in a nontrivial application and
wstd::http::Client, I added the exampleaxum/examples/weather.rswhich implements a toy weather http service by making calls to free geocoding and weather APIs run byopen-meteo.com.This example is derived from a standalone demo I wrote for an earlier wstd at
https://github.com/pchickey/wasi-http-demos, and I'll probably upstream it back to there after we get releases out.Test refactoring
Incidentally, as part of this PR, I cleaned up some mess around testing.
Previously, there was a
test-programscrate which existed to have bins whichinclude!the sources of some of the examples in thewstdcrate. Thetest-programs-artifactscrate existed to buildtest-programswith--target wasm32-wasip2with itsbuild.rsand enumerate the binaries as str constants exported by the lib, and then write native integration tests that run those in wasmtime and hit wasmtime with the appropriate external stimulus (http requests or tcp sockets).There was no need to have the intermediate
test-programscrate. Thetest-programs-artifactscan just build and use the wstd examples directly. When adding the wstd-axum crate's examples, I noticed this was totally unnecessary, and I can't figure out why I did it historically. So, test-programs got erased and test-programs-artifacts became test-programs.In a future PR, I will need to add tests that exercise the other wstd examples (http_client, complex_http_client).
Edition 2024 upgrade
The workspace has been upgraded to 2024 edition, because I just noticed it was not yet upgraded. This really could have been separated out into another PR that would require a rubber stamp, so I folded it in. Its almost entirely rustfmt order changes, and some rules around match and ref mut changed in a trivial manner. These changes are separated out into their own commit.