-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
215 lines (204 loc) · 6.83 KB
/
index.html
File metadata and controls
215 lines (204 loc) · 6.83 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
<script type="module" src="/src/main.ts"></script>
<style>
body {
font-family: sans-serif;
margin: 0 auto;
padding: 2rem 1rem;
max-width: 800px;
}
button {
cursor: pointer;
background: rgba(0, 0, 0, 0);
border: 3px solid #666;
border-radius: 3px;
padding: 0.5rem;
margin: 0 0 1rem;
transition: all 0.1s ease;
}
button:hover {
background: rgba(0, 0, 0, 0.1);
border-color: 999;
}
button[data-ariamanager="activated"] {
border-color: green;
}
[aria-hidden="true"] {
display: none;
}
.exampletarget {
border: 1px solid #ccc;
padding: 1rem;
}
</style>
</head>
<body>
<div id="root">
<h1>Fetch Manager Examples</h1>
<p>
This page shows an examples of how the Fetch manager can be utilized.
</p>
</div>
<div id="examples">
<section>
<h2>Example 1. Simplest fetch</h2>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const fetchManager = new window.fetchmanager();
const result = await fetchManager.Fetch({ url: "/data.json" });
console.log("Simple fetch result:", result);
document.getElementById("exampletarget1").innerHTML =
"Result:\n" + JSON.stringify(result);
});
</script>
<pre>
<code>
const result = await fetchManager.Fetch({ "url": "/data.json" });
</code>
</pre>
<pre id="exampletarget1" class="exampletarget"></pre>
</section>
<section>
<h2>Example 2. Delay fetch request with 2 seconds</h2>
<script>
document.addEventListener("DOMContentLoaded", async () => {
document.getElementById("exampletarget2").innerHTML +=
"Init: " + new Date().toISOString() + "\n";
const fetchManager = new window.fetchmanager();
document.getElementById("exampletarget2").innerHTML +=
"Fetch command initiated: " + new Date().toISOString() + "\n";
const response = await fetchManager.Fetch({
url: "/data.json",
requestdelay: 2000,
});
const result = await response;
console.log("Simple fetch result:", result);
document.getElementById("exampletarget2").innerHTML +=
"Fetch response: " + new Date().toISOString() + "\n";
document.getElementById("exampletarget2").innerHTML +=
"Result:\n" + JSON.stringify(result);
});
</script>
<pre>
<code>
const result = await fetchManager.Fetch({ "url": "/data.json", "requestdelay": 2000 });
</code>
</pre>
<pre id="exampletarget2" class="exampletarget"></pre>
</section>
<section>
<h2>Example 3. Debounced fetch (automatic abort)</h2>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const fetchManager = new window.fetchmanager();
let response = await fetchManager.Fetch({
url: "/data.json",
key: "example3request",
});
result = await fetchManager.Fetch({
url: "/data.json",
key: "example3request",
});
document.getElementById("exampletarget3").innerHTML =
"Result:\n" + JSON.stringify(result);
});
document.addEventListener("DOMContentLoaded", async () => {
const fetchManager = new window.fetchmanager();
const response = await fetchManager.Fetch({
url: "/data.json",
key: "example3request",
});
const result = response;
const response2 = await fetchManager.Fetch({
url: "/data.json",
key: "example3request",
});
const result2 = response;
document.getElementById("exampletarget3").innerHTML += "Results: ";
document.getElementById("exampletarget3").innerHTML +=
"1: " + JSON.stringify(result);
document.getElementById("exampletarget3").innerHTML +=
"2: " + JSON.stringify(result2);
});
</script>
<pre>
<code>
const result = await fetchManager.Fetch({ "url": "/data.json" });
</code>
</pre>
<pre id="exampletarget3" class="exampletarget"></pre>
</section>
<section>
<h2>Example 4. Request with parsed querystring object</h2>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const fetchManager = new window.fetchmanager();
const response = await fetchManager.Fetch({
key: "example4",
url: "/data.json",
querystring: {
numbervar: 123,
boolvar: true,
stringvar: "stringcontent",
arrayvar: ["foo", "bar"],
},
returnrequest: true,
});
const result = await response.json();
document.getElementById("exampletarget4").innerHTML +=
"Requested url:\n" + response.url + "\n\n";
document.getElementById("exampletarget4").innerHTML +=
"Result:\n" + JSON.stringify(result);
});
</script>
<pre>
<code>
const result = await fetchManager.Fetch({
"url": "/data.json",
"querystring": {
"numbervar": 123,
"boolvar": true,
"stringvar": "stringcontent",
"arrayvar":["foo", "bar"]
}
});
</code>
</pre>
<pre id="exampletarget4" class="exampletarget"></pre>
</section>
<section>
<h2>Example 5. Cache request</h2>
<script>
document.addEventListener("DOMContentLoaded", async () => {
const fetchManager = new window.fetchmanager();
const response = await fetchManager.Fetch({
key: "example5",
url: "/text.txt",
cache: true,
});
const result = await response.clone().text();
document.getElementById("exampletarget5").innerHTML +=
"Requested url:\n" + response.url + "\n\n";
document.getElementById("exampletarget5").innerHTML +=
"Result:\n" + JSON.stringify(result);
});
</script>
<pre>
<code>
const result = await fetchManager.Fetch({
"url": "/text.txt",
"cache":true
});
</code>
</pre>
<pre id="exampletarget5" class="exampletarget"></pre>
</section>
</div>
</body>
</html>