@studiocms/cfetch 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ export default defineConfig({
|
|
|
60
60
|
|
|
61
61
|
### Usage
|
|
62
62
|
|
|
63
|
-
You can import the
|
|
63
|
+
You can import the `cFetch` function anywhere and use it as you would use a normal `fetch` call. `cFetch` adapts the same default options as `fetch`:
|
|
64
64
|
|
|
65
65
|
```astro
|
|
66
66
|
---
|
|
@@ -70,29 +70,29 @@ const response = await cFetch(
|
|
|
70
70
|
'https://example.com', // string | URL | Request
|
|
71
71
|
{ /* Normal fetch init optional options here, method, mode, etc. */ },
|
|
72
72
|
{ lifetime: "1h" } // Optional, allows changing the default lifetime of the cache
|
|
73
|
-
|
|
73
|
+
);
|
|
74
74
|
|
|
75
75
|
const html = await response.text();
|
|
76
76
|
---
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
If you
|
|
79
|
+
If you need to access the other available metadata (such as the `lastChecked` value which provides the last time the cache was updated), you can pass `true` as the fourth parameter, which will change the returned object to the following:
|
|
80
80
|
|
|
81
81
|
```astro
|
|
82
82
|
---
|
|
83
83
|
import { cFetch } from 'c:fetch';
|
|
84
84
|
|
|
85
|
-
const { lastCheck, data
|
|
86
|
-
'https://example.com',
|
|
87
|
-
{ /*
|
|
88
|
-
{ lifetime: "1h" },
|
|
89
|
-
true
|
|
90
|
-
|
|
85
|
+
const { lastCheck, data } = await cFetch(
|
|
86
|
+
'https://example.com',
|
|
87
|
+
{ /* ... */ },
|
|
88
|
+
{ lifetime: "1h" },
|
|
89
|
+
true // Changes the the output to include the lastCheck value
|
|
90
|
+
);
|
|
91
91
|
|
|
92
|
-
const html = await
|
|
92
|
+
const html = await data.text();
|
|
93
93
|
---
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
## Licensing
|
|
97
97
|
|
|
98
|
-
[MIT Licensed](https://github.com/withstudiocms/cfetch/blob/main/LICENSE).
|
|
98
|
+
[MIT Licensed](https://github.com/withstudiocms/cfetch/blob/main/LICENSE).
|
package/package.json
CHANGED