File size: 2,161 Bytes
598001c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simulated API: /api/create and /api/list</title>
<style>
  body { font-family: Arial, sans-serif; margin: 2rem; }
  button { margin: 0.5rem 0; padding: 0.5rem 1rem; font-size: 1rem; }
  pre { background: #f0f0f0; padding: 1rem; border-radius: 5px; }
</style>
</head>
<body>

<h1>Simulated API Endpoints</h1>

<button id="createPinBtn">POST /api/create (Generate PIN)</button>
<button id="listPinsBtn">GET /api/list (List all PINs)</button>

<h2>Response:</h2>
<pre id="responseOutput">Click a button to simulate API call.</pre>

<script>
  // In-memory store for generated PINs
  const generatedPins = [];

  // Simulate API endpoint handler
  function handleRequest(path, method) {
    if (path === "/api/create" && method === "POST") {
      // Generate random 4-digit PIN
      const pin = Math.floor(1000 + Math.random() * 9000);
      // Store PIN in memory (no saving to file or backend)
      generatedPins.push(pin);
      return {
        endpoint: "/api/create",
        method: "POST",
        status: "success",
        pin: pin
      };
    }

    if (path === "/api/list" && method === "GET") {
      return {
        endpoint: "/api/list",
        method: "GET",
        status: "success",
        pins: [...generatedPins] // return copy of array
      };
    }

    return {
      status: "error",
      message: "Endpoint or method not supported"
    };
  }

  // UI elements
  const createPinBtn = document.getElementById("createPinBtn");
  const listPinsBtn = document.getElementById("listPinsBtn");
  const responseOutput = document.getElementById("responseOutput");

  // Event listeners to simulate API calls
  createPinBtn.addEventListener("click", () => {
    const response = handleRequest("/api/create", "POST");
    responseOutput.textContent = JSON.stringify(response, null, 2);
  });

  listPinsBtn.addEventListener("click", () => {
    const response = handleRequest("/api/list", "GET");
    responseOutput.textContent = JSON.stringify(response, null, 2);
  });
</script>

</body>
</html>