aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-10-09 23:30:36 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-10-09 23:30:36 -0400
commit5617124a794b8d256e3d24b143b8dd2403cce993 (patch)
tree673a288cdbc853d697c2d8294312f563ae9f4e60 /src/client/Network.ts
parent2cc7ca6b267d9dd6b1683d59b6966a021339bc18 (diff)
parent3b1345616bf2f7101a21c182e0c9719b1e31f899 (diff)
merged
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r--src/client/Network.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts
new file mode 100644
index 000000000..75ccb5e99
--- /dev/null
+++ b/src/client/Network.ts
@@ -0,0 +1,33 @@
+import { Utils } from "../Utils";
+import { CurrentUserUtils } from "../server/authentication/models/current_user_utils";
+import requestPromise = require('request-promise');
+
+export namespace Identified {
+
+ export async function FetchFromServer(relativeRoute: string) {
+ return (await fetch(relativeRoute, { headers: { userId: CurrentUserUtils.id } })).text();
+ }
+
+ export async function PostToServer(relativeRoute: string, body?: any) {
+ let options = {
+ uri: Utils.prepend(relativeRoute),
+ method: "POST",
+ headers: { userId: CurrentUserUtils.id },
+ body,
+ json: true
+ };
+ return requestPromise.post(options);
+ }
+
+ export async function PostFormDataToServer(relativeRoute: string, formData: FormData) {
+ const parameters = {
+ method: 'POST',
+ headers: { userId: CurrentUserUtils.id },
+ body: formData,
+ };
+ const response = await fetch(relativeRoute, parameters);
+ const text = await response.json();
+ return text;
+ }
+
+} \ No newline at end of file