Files
reqwest-impersonate/examples/wasm_header/src/lib.rs
John Gallagher f6f81f9cc1 wasm: Add request body in the form of Bytes (#696)
* Add body bytes

* Add example and header creation code
2019-11-04 09:17:05 -08:00

24 lines
802 B
Rust

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))
}