feat(plugins): use @tauri-apps namespace on NPM (#368)

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
This commit is contained in:
Lucas Fernandes Nogueira
2023-05-17 20:52:53 -03:00
committed by GitHub
parent caf8456864
commit 22991af9f4
72 changed files with 435 additions and 419 deletions
+31 -31
View File
@@ -1,60 +1,60 @@
<script>
import { getClient, Body, ResponseType } from 'tauri-plugin-http-api'
import { JsonView } from '@zerodevx/svelte-json-view'
import { getClient, Body, ResponseType } from "@tauri-apps/plugin-http";
import { JsonView } from "@zerodevx/svelte-json-view";
let httpMethod = 'GET'
let httpBody = ''
let httpMethod = "GET";
let httpBody = "";
export let onMessage
export let onMessage;
async function makeHttpRequest() {
const client = await getClient().catch((e) => {
onMessage(e)
throw e
})
let method = httpMethod || 'GET'
onMessage(e);
throw e;
});
let method = httpMethod || "GET";
const options = {
url: 'http://localhost:3003',
method: method || 'GET'
}
url: "http://localhost:3003",
method: method || "GET",
};
if (
(httpBody.startsWith('{') && httpBody.endsWith('}')) ||
(httpBody.startsWith('[') && httpBody.endsWith(']'))
(httpBody.startsWith("{") && httpBody.endsWith("}")) ||
(httpBody.startsWith("[") && httpBody.endsWith("]"))
) {
options.body = Body.json(JSON.parse(httpBody))
} else if (httpBody !== '') {
options.body = Body.text(httpBody)
options.body = Body.json(JSON.parse(httpBody));
} else if (httpBody !== "") {
options.body = Body.text(httpBody);
}
client.request(options).then(onMessage).catch(onMessage)
client.request(options).then(onMessage).catch(onMessage);
}
/// http form
let foo = 'baz'
let bar = 'qux'
let result = null
let multipart = true
let foo = "baz";
let bar = "qux";
let result = null;
let multipart = true;
async function doPost() {
const client = await getClient().catch((e) => {
onMessage(e)
throw e
})
onMessage(e);
throw e;
});
result = await client.request({
url: 'http://localhost:3003',
method: 'POST',
url: "http://localhost:3003",
method: "POST",
body: Body.form({
foo,
bar
bar,
}),
headers: multipart
? { 'Content-Type': 'multipart/form-data' }
? { "Content-Type": "multipart/form-data" }
: undefined,
responseType: ResponseType.Text
})
responseType: ResponseType.Text,
});
}
</script>