forked from ambar/create-fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
33 lines (32 loc) · 858 Bytes
/
example.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Demo</title>
</head>
<body>
<pre>
npx serve .
open http://localhost:5000/example
</pre>
<pre id="log"></pre>
<script type="module">
import createFetch, {query, bodify, headers} from './dist/index.js'
const myFetch = createFetch(fetch, [
query(),
bodify(),
headers({'x-requested-with': 'fetch'}),
])
myFetch('/', {
method: 'POST',
query: {foo: 'bar'},
body: new URLSearchParams({lang: '中文'}),
}).then(r => {
console.info(r)
log.textContent = [...r.headers].join('\n')
})
</script>
</body>
</html>