Skip to content

Commit 01a3626

Browse files
authored
✅ Add base test & update README (#36)
1 parent 897c8b5 commit 01a3626

9 files changed

+1927
-115
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ if (response.ok) {
661661
Accepts all the options from native [fetch](http://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters) in the desktop browsers, or [`node-fetch`](https://github.com/node-fetch/node-fetch#options) in node.js. Additionally you can specify:
662662

663663
- [resource](#resource-string)
664+
- [base](#base-string)
664665
- [headers](#headers-headersinit)
665666
- [json](#json-unknown)
666667
- [params](#params-urlsearchparams--object--string)
@@ -704,6 +705,27 @@ const result = await posts.get().json() // → [{ id: 0, title: 'Title', ... }]
704705
- [`instance`](#returns-instance)
705706
- [`instance.extend`](#extend)
706707

708+
#### base?: string
709+
710+
Base of a [URL](http://developer.mozilla.org/en-US/docs/Web/API/URL), use it only if you want to specify relative url inside [resource](#resource-string). By default equals to `location.origin` if available. Not merged when you [extend](#extend) an instance. Most of the time use [resource](#resource-string) option instead.
711+
712+
```ts
713+
// send a request to `new URL('/posts', location.origin)` if possible
714+
await YF.get('/posts')
715+
716+
// send a request to `https://jsonplaceholder.typicode.com/posts`
717+
await YF.get('https://jsonplaceholder.typicode.com/posts')
718+
719+
// send a request to `new URL('/posts', 'https://jsonplaceholder.typicode.com')`
720+
await YF.get('/posts', { base: 'https://jsonplaceholder.typicode.com' })
721+
```
722+
723+
##### Related
724+
725+
- [Create and instance](#create-an-instance)
726+
- [Extend and instance](#extend-an-instance)
727+
- [`options.resource`](#resource-string)
728+
707729
#### headers?: HeadersInit
708730
709731
Request headers, the same as in [Fetch](http://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), except multiple `headers` will merge when you [extend](#extend) an instance.

0 commit comments

Comments
 (0)