aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
authorStanley Yip <stanley_yip@brown.edu>2019-10-02 21:59:58 -0400
committerStanley Yip <stanley_yip@brown.edu>2019-10-02 21:59:58 -0400
commit16dd968fed4a94cc0e8e870aa0c0e676d533aad1 (patch)
treee9d701d62411fddfa667beede71fbbc7e48f1eea /src/client/Network.ts
parent2d3deb7291b7d98acf71566a67c4d648a90ef5af (diff)
parent9427474b473d70974784a1517a1be902fb8d18ee (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into interaction
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