2018-09-10 17:51:44 -07:00
|
|
|
# The `fetch` API
|
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[View full source code][code] or [view the compiled example online][online]
|
2018-09-20 16:20:42 -07:00
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/fetch/
|
2018-09-20 16:20:42 -07:00
|
|
|
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/fetch
|
|
|
|
|
2018-09-10 17:51:44 -07:00
|
|
|
This example uses the `fetch` API to make an HTTP request to the GitHub API and
|
|
|
|
then parses the resulting JSON.
|
|
|
|
|
|
|
|
## `Cargo.toml`
|
|
|
|
|
|
|
|
The `Cargo.toml` enables a number of features related to the `fetch` API and
|
|
|
|
types used: `Headers`, `Request`, etc. It also enables `wasm-bindgen`'s `serde`
|
|
|
|
support.
|
|
|
|
|
|
|
|
```toml
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/fetch/Cargo.toml}}
|
2018-09-10 17:51:44 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
## `src/lib.rs`
|
|
|
|
|
|
|
|
```rust
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/fetch/src/lib.rs}}
|
2018-09-10 17:51:44 -07:00
|
|
|
```
|