diff options
author | Abdullah Ahmed <abdullah_ahmed@brown.edu> | 2019-10-05 19:17:11 -0400 |
---|---|---|
committer | Abdullah Ahmed <abdullah_ahmed@brown.edu> | 2019-10-05 19:17:11 -0400 |
commit | 57b57b2d82b385ec9aa9d59c0899dc8f48a31223 (patch) | |
tree | ea9fef42849fc1341c6da1300bc4e5f25048cb14 /src/client/Network.ts | |
parent | a44e12f4625caca5d75a456f0ba1ab977149ae6e (diff) | |
parent | 961cb1566e16edb353975ec436a4445c1cf3db0f (diff) |
meged
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r-- | src/client/Network.ts | 33 |
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 |