cloudflare / wrangler-legacy

🀠 Home to Wrangler v1 (deprecated)
https://workers.cloudflare.com
Apache License 2.0
3.2k stars 335 forks source link

POST query with body message #48

Closed robertaboukhalil closed 5 years ago

robertaboukhalil commented 5 years ago

Hello,

Thanks for the awesome library! I'm working with the demo example in Rust and have a question about sending POST requests with a body message.

In worker.js, I'm returning the request object as a JSON string:

async function handleRequest(request) {
    return new Response(JSON.stringify(request), {status: 200})
}

But calling it on the command line doesn't seem to pass the body along:

root@f396da212a3a:/src/demo# wrangler preview post "hello world"
πŸŒ€ Compiling your project to WebAssembly...
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished release [optimized] target(s) in 2.08s
[INFO]: Installing wasm-bindgen...
[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended
[INFO]: :-) Done in 2.36s
[INFO]: :-) Your wasm pkg is ready to publish at ./pkg.
πŸ‘·β€β™€οΈ POST https://00000000000000000000000000000000.cloudflareworkers.com
πŸ‘·β€β™€οΈ Your worker responded with: {"fetcher":{},"redirect":"manual","headers":{},"url":"https://example.com/","method":"POST","bodyUsed":false,"body":{"locked":false}}

Is this the right way to do it?

In case it helps, I'm using wrangler 0.1.0:

root@f396da212a3a:/src/demo# wrangler --version
πŸ‘·β€β™€οΈπŸ§‘β˜οΈ ✨ wrangler 0.1.0
robertaboukhalil commented 5 years ago

Oups, turns out I was doing it wrong! It works when I do the following: