wasm: Add request body in the form of Bytes (#696)
* Add body bytes * Add example and header creation code
This commit is contained in:
committed by
Sean McArthur
parent
b24b0be461
commit
f6f81f9cc1
23
examples/wasm_header/src/lib.rs
Normal file
23
examples/wasm_header/src/lib.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// NOTE: This test is a clone of https://github.com/rustwasm/wasm-bindgen/blob/master/examples/fetch/src/lib.rs
|
||||
// but uses Reqwest instead of the web_sys fetch api directly
|
||||
|
||||
/**
|
||||
* curl --location --request POST "https://postman-echo.com/post" \
|
||||
--data "This is expected to be sent back as part of response body."
|
||||
*/
|
||||
#[wasm_bindgen]
|
||||
pub async fn run() -> Result<JsValue, JsValue> {
|
||||
let res = reqwest::Client::new()
|
||||
.post("https://postman-echo.com/post")
|
||||
.body("This is expected to be sent back as part of response body.")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
// .header("Access-Control-Allow-Origin", "*")
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let text = res.text().await?;
|
||||
|
||||
Ok(JsValue::from_str(&text))
|
||||
}
|
||||
Reference in New Issue
Block a user