1
1
<h1 align =" center " >ya-fetch</h1 >
2
2
3
- [ ![ ] ( https://flat.badgen.net/bundlephobia/minzip/ya-fetch )] ( https://bundlephobia.com/result?p=ya-fetch )
4
-
5
3
> Super light-weight wrapper around ` fetch `
6
4
7
5
- [x] Only 1 kB when minified & gziped
11
9
- [x] First-class [ JSON support] ( #send--receive-json ) (automatic serialization, content type headers)
12
10
- [x] [ Search params] ( #params-urlsearchparams--object--string ) serialization
13
11
- [x] Global [ timeouts] ( #timeout-number )
12
+ - [x] [ Works in a browser] ( #-import-in-a-browser ) without a bundler
14
13
- [x] Written in TypeScript
15
14
- [x] Pure ESM module
16
15
- [x] Zero deps
@@ -25,10 +24,12 @@ $ npm install --save ya-fetch
25
24
26
25
``` html
27
26
<script type =" module" >
28
- import * as YF from ' https://unpkg.com/ya-fetch/esm/index .js'
27
+ import * as YF from ' https://unpkg.com/ya-fetch/esm/min .js'
29
28
</script >
30
29
```
31
30
31
+ For readable version import from ` https://unpkg.com/ya-fetch/esm/index.js ` .
32
+
32
33
[ 🔗 Playground on CodePen] ( https://codepen.io/exah/pen/gOKRYjW?editors=0012 ) .
33
34
34
35
## ⬇️ Jump to
@@ -42,7 +43,7 @@ $ npm install --save ya-fetch
42
43
### Import module
43
44
44
45
``` ts
45
- import * as YF from ' ya-fetch'
46
+ import * as YF from ' ya-fetch' // or from 'https://unpkg.com/ya-fetch/esm/min.js' in browsers
46
47
` ` `
47
48
48
49
### Create an instance
@@ -378,13 +379,13 @@ const instance = YF.create({
378
379
})
379
380
380
381
// will have combined ` resource ` and merged ` headers `
381
- const extension = instance.extend({
382
+ const extended = instance.extend({
382
383
resource: '/posts'
383
384
headers: { 'X-Something-Else': 'Bar' },
384
385
})
385
386
386
387
// will send request to: 'https://jsonplaceholder.typicode.com/posts/1'
387
- await extension .post(1)
388
+ await extended .post(1, { json: { title: 'Hello' } } )
388
389
` ` `
389
390
390
391
##### Related
@@ -691,7 +692,7 @@ const posts = instance.extend({
691
692
})
692
693
693
694
// will send request to 'https://jsonplaceholder.typicode.com/posts'
694
- await posts.get()
695
+ const result = await posts.get().json() // → [{ id: 0, title: 'Title', ... }]
695
696
` ` `
696
697
697
698
##### Related
0 commit comments