feat: update fetch-rs

This commit is contained in:
2023-06-04 14:09:25 +08:00
parent c259d6c102
commit 8aba71a72b
2 changed files with 65 additions and 22 deletions

View File

@@ -1,18 +1,34 @@
```js
const response = fetch("http://example.com/movies.json")
const responseJson = response.json();
```rust
let response = fetch(
"https://hatter.ink/util/print_request.action",
&FetchOptions::default())?;
```
```js
const response = fetch(url, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: "follow", // manual, *follow, error
body: JSON.stringify(data), // body data type must match "Content-Type" header
});
```rust
let response = fetch(
"https://hatter.ink/util/print_request.action",
&FetchOptions {
method: FetchMethod::Put,
body: Some("{}".as_bytes().to_vec()),
..Default::default()
})?;
```
```rust
let response = fetch(
"https://hatter.ink/util/print_request.action",
&FetchOptions {
method: FetchMethod::Post,
headers: Some(vec![
FetchHeader {
key: "content-type".to_string(),
value: "application/json".to_string(),
}
]),
body: Some("{}".as_bytes().to_vec()),
..Default::default()
})?;
```