File size: 904 Bytes
2e9b0fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Space template</title>
</head>
<body>
  DEMO fastapi with static HTML. POST request to /api/test:<br/>
  <pre id="demo_output"></pre>
  <script>
    document.getElementById("demo_output").innerHTML = "Loading...";

    const DEMO_JSON = {
      "key1": "value1",
      "key2": "value2"
    };

    fetch('/api/test', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(DEMO_JSON),
    })
      .then(response => response.json())
      .then(data => {
        document.getElementById("demo_output").innerHTML = JSON.stringify(data, null, 2);
      })
      .catch(error => {
        document.getElementById("demo_output").innerHTML = 'Error: ' + error;
      });
  </script>
</body>
</html>