Remove non-working example. Postman-echo does not return CORS headers. After a quick search I did not find a test echo server which returned CORS headers. (#1002)
I have rolled an example header into the other WASM example
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
## Example usage of Reqwest from WASM
|
||||
|
||||
You can build the example locally with:
|
||||
Install wasm-pack with
|
||||
|
||||
npm install
|
||||
|
||||
Then you can build the example locally with:
|
||||
|
||||
|
||||
npm run serve
|
||||
|
||||
@@ -36,6 +36,7 @@ pub struct Signature {
|
||||
pub async fn run() -> Result<JsValue, JsValue> {
|
||||
let res = reqwest::Client::new()
|
||||
.get("https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master")
|
||||
.header("Accept", "application/vnd.github.v3+json")
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
|
||||
5
examples/wasm_header/.gitignore
vendored
5
examples/wasm_header/.gitignore
vendored
@@ -1,5 +0,0 @@
|
||||
node_modules
|
||||
pkg
|
||||
target
|
||||
Cargo.lock
|
||||
*.swp
|
||||
@@ -1,16 +0,0 @@
|
||||
[package]
|
||||
name = "wasm"
|
||||
version = "0.1.0"
|
||||
authors = ["John Gallagher <john.willis.gallagher@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# Config mostly pulled from: https://github.com/rustwasm/wasm-bindgen/blob/master/examples/fetch/Cargo.toml
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
reqwest = {path = "../../"}
|
||||
wasm-bindgen-futures = "0.4.1"
|
||||
wasm-bindgen = { version = "0.2.51", features = ["serde-serialize"] }
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
## Example usage of Reqwest from WASM
|
||||
|
||||
You can build the example locally with:
|
||||
|
||||
|
||||
npm run serve
|
||||
|
||||
and then visiting http://localhost:8080 in a browser should run the example!
|
||||
|
||||
|
||||
This example is loosely based off of [this example](https://github.com/rustwasm/wasm-bindgen/blob/master/examples/fetch/src/lib.rs), an example usage of `fetch` from `wasm-bindgen`.
|
||||
@@ -1,9 +0,0 @@
|
||||
const rust = import('./pkg');
|
||||
|
||||
rust
|
||||
.then(m => {
|
||||
return m.run().then((data) => {
|
||||
console.log(data);
|
||||
})
|
||||
})
|
||||
.catch(console.error);
|
||||
6070
examples/wasm_header/package-lock.json
generated
6070
examples/wasm_header/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"serve": "webpack-dev-server"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@wasm-tool/wasm-pack-plugin": "1.0.1",
|
||||
"text-encoding": "^0.7.0",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"webpack": "^4.29.4",
|
||||
"webpack-cli": "^3.1.1",
|
||||
"webpack-dev-server": "^3.1.0"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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))
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const webpack = require('webpack');
|
||||
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
|
||||
|
||||
module.exports = {
|
||||
entry: './index.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'index.js',
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin(),
|
||||
new WasmPackPlugin({
|
||||
crateDirectory: path.resolve(__dirname, ".")
|
||||
}),
|
||||
// Have this example work in Edge which doesn't ship `TextEncoder` or
|
||||
// `TextDecoder` at this time.
|
||||
new webpack.ProvidePlugin({
|
||||
TextDecoder: ['text-encoding', 'TextDecoder'],
|
||||
TextEncoder: ['text-encoding', 'TextEncoder']
|
||||
})
|
||||
],
|
||||
mode: 'development'
|
||||
};
|
||||
Reference in New Issue
Block a user