NB: this example uses an experimental wasi-http
that is part of the WASI specification
but is still going through iteration. Expect breaking changes in future releases.
dotnet build
$ dotnet run
data from read: {
"args": {},
"headers": {
"x-forwarded-proto": "https",
"x-forwarded-port": "443",
"host": "postman-echo.com",
"x-amzn-trace-id": "Root=1-647a242d-0700da8c2aeb9ed34390e69f",
"user-agent": "WASI-HTTP/0.0.1",
"content-type": "application/json"
},
"url": "https://postman-echo.com/get"
}
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
Date: Fri, 02 Jun 2023 17:17:33 GMT
Set-Cookie: sails.sid=s%3AIkf163sGfmOzI5ePigclF_529u-yb-iM.ZtP5UII4ZAdJiea%2BT4sKh5CAcFwDoJ%2F%2Bqsi13flMLzY; Path=/; HttpOnly
Connection: keep-alive
ETag: W/"13d-PU41PZI6y0DFxFj3/QP2IeKi4K4"
Content-Type: application/json; charset=utf-8
Content-Length: 317
}
{
"args": {},
"headers": {
"x-forwarded-proto": "https",
"x-forwarded-port": "443",
"host": "postman-echo.com",
"x-amzn-trace-id": "Root=1-647a242d-0700da8c2aeb9ed34390e69f",
"user-agent": "WASI-HTTP/0.0.1",
"content-type": "application/json"
},
"url": "https://postman-echo.com/get"
}
data from read: {
"args": {},
"data": {
"userId": 77,
"id": 1,
"title": "write code sample",
"completed": false
},
"files": {},
"form": {},
"headers": {
"x-forwarded-proto": "https",
"x-forwarded-port": "443",
"host": "postman-echo.com",
"x-amzn-trace-id": "Root=1-647a242e-38dd540d69fef19d1b4e5dff",
"content-length": "66",
"content-type": "application/json",
"user-agent": "WASI-HTTP/0.0.1"
},
"json": {
"userId": 77,
"id": 1,
"title": "write code sample",
"completed": false
},
"url": "https://postman-echo.com/post"
}
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
Set-Cookie: sails.sid=s%3AG4QvfJFNkjxVo6HCPnYIjK1rzbMzK825.DEG15cFXX7r6G%2FBx4y2n8W2IE8jsNm4l1oulYIS9Us4; Path=/; HttpOnly
ETag: W/"249-bMTMd9tqmXVgIdv3EJJMJp5ixx4"
Connection: keep-alive
Date: Fri, 02 Jun 2023 17:17:34 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 585
}
{
"args": {},
"data": {
"userId": 77,
"id": 1,
"title": "write code sample",
"completed": false
},
"files": {},
"form": {},
"headers": {
"x-forwarded-proto": "https",
"x-forwarded-port": "443",
"host": "postman-echo.com",
"x-amzn-trace-id": "Root=1-647a242e-38dd540d69fef19d1b4e5dff",
"content-length": "66",
"content-type": "application/json",
"user-agent": "WASI-HTTP/0.0.1"
},
"json": {
"userId": 77,
"id": 1,
"title": "write code sample",
"completed": false
},
"url": "https://postman-echo.com/post"
}
proxy.h
, proxy.c
and proxy_component_type.o
are all generated by wit-bindgen
.
You probably don't need to regenerate, but if you do:
git clone https://github.com/WebAssembly/wasi-http
cd wasi-http
# corresponds to wasmtime 9.0.x
git checkout 244e068
/usr/local/lib/wit-bindgen c --world proxy ./wit
- Headers on the request are not currently supported.
- Validate no memory leaks.
- Expose more of the 'native' wasi-http interface?