Create http request with rustwasm saving boilerplate
Cargo.toml
toml
wasm_request = '0.1'
```rust
struct Eur { eur: f64, }
struct CurrentPrice { current_price: Eur, }
struct Price { market_data: CurrentPrice, }
async fn gettokenprice() -> Price {
let options = get_options::
let price_1mt_token: Price = request(options).await.unwrap().into_serde().unwrap();
price_1mt_token
} ```
```rust use wasmrequest::{getoptions, request, Method, DataType};
pub struct User { pub email: String, pub username: String, pub password: String, }
async fn createuser() { let user = User { email: "test@example.com".tostring(), password: "test43214".to_string(), }
let options = get_options::
request(options).await.unwrap().into_serde().unwrap();
}
```
```rust use wasmrequest::{getoptions, request, Method, DataType, getdefualtheaders}; use web_sys::FormData;
async fn addform() { let form = FormData::new().unwrap(); form.appendwithstr("name", "Lee").unwrap(); form.appendwith_str("email", "test.example@gmail.com").unwrap();
let headers = getdefualtheaders(); headers.delete("Content-Type").unwrap();
let options = get_options::<()>( "https://api.sport-example.com/user", Method::Post, None, Some(DataType::Form(form)), );
request(options).await.unwrap().into_serde().unwrap(); } ```
rust
set_storage("food", "ramen");
let food = get_storage("food").unwrap();
delete_storage("food");
wasm-pack test --headless --chrome --firefox
If you like Yew Styles, help me supporting the project: - BAT rewards in case that you use Brave Browser - Using this link to create an account in Binance (get 10% fee back for every trading) - Github Sponsors
Wasm Request is MIT licensed