summaryrefslogtreecommitdiff
path: root/frontend/src/serverHelper.ts
blob: 31810934dcab5671cdce75261dc532b80cfbf46a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import axios from "axios";

const SERVER_URL = "";

export const getWords = async (): Promise<[...(string[] & { length: 9 })]> => {
  const words = (await axios.get(`${SERVER_URL}/api/random-words`))
    .data as string[];
  if (words.length !== 16) {
    throw new Error(`Got invalid words ${words} from server`);
  }
  return words;
};

export const getCategory = async (
  words: string[]
): Promise<{ categoryName: string; reason: string }> => {
  const response = (
    await axios.post(`${SERVER_URL}/api/group-words`, {
      words,
    })
  ).data;

  return response;
};