chore(release): 0.2.5
[risinglegends.git] / src / client / http.ts
1 export function authToken(): string {
2   return localStorage.getItem('authToken');
3 }
4
5 export const http = {
6   get: async (path: string) => {
7     const res = await fetch(path, {
8       headers: {
9         'x-authtoken': authToken()
10       }
11     });
12     return res.json();
13   },
14   post: async (path: string, data: any) => {
15     const res = await fetch(path, {
16       method: 'post',
17       body: JSON.stringify(data),
18       headers: {
19         'x-authtoken': authToken(),
20         'content-type': 'application/json'
21       }
22     });
23
24     try {
25       return res.json();
26     }
27     catch {
28       console.log('No valid JSON response');
29       return null;
30     }
31   }
32 }