grab-url 0.8.3
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/dist/grab-api.cjs.js +2 -0
- package/dist/grab-api.cjs.js.map +1 -0
- package/dist/grab-api.d.ts +321 -0
- package/dist/grab-api.es.js +495 -0
- package/dist/grab-api.es.js.map +1 -0
- package/dist/icons.cjs.js +2 -0
- package/dist/icons.cjs.js.map +1 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.es.js +2 -0
- package/dist/icons.es.js.map +1 -0
- package/package.json +83 -0
- package/readme.md +156 -0
- package/src/grab-api.ts +783 -0
- package/src/grab-url.js +2084 -0
- package/src/icons/cli/spinners.json +1074 -0
- package/src/icons/index.ts +58 -0
- package/src/icons/svg/index.ts +313 -0
- package/src/icons/svg/loading-bouncy-ball.svg +3 -0
- package/src/icons/svg/loading-double-ring.svg +6 -0
- package/src/icons/svg/loading-eclipse.svg +3 -0
- package/src/icons/svg/loading-ellipsis.svg +16 -0
- package/src/icons/svg/loading-floating-search.svg +11 -0
- package/src/icons/svg/loading-gears.svg +3 -0
- package/src/icons/svg/loading-infinity.svg +3 -0
- package/src/icons/svg/loading-orbital.svg +8 -0
- package/src/icons/svg/loading-pacman.svg +22 -0
- package/src/icons/svg/loading-pulse-bars.svg +12 -0
- package/src/icons/svg/loading-red-blue-ball.svg +10 -0
- package/src/icons/svg/loading-reload-arrow.svg +5 -0
- package/src/icons/svg/loading-ring.svg +3 -0
- package/src/icons/svg/loading-ripple.svg +7 -0
- package/src/icons/svg/loading-spinner-oval.svg +49 -0
- package/src/icons/svg/loading-spinner.svg +57 -0
- package/src/icons/svg/loading-square-blocks.svg +17 -0
- package/src/log.ts +309 -0
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "grab-url",
|
|
3
|
+
"description": "📥 Generate Request to API from Browser",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.8.3",
|
|
6
|
+
"author": "vtempest",
|
|
7
|
+
"license": "rights.institute/prosper",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/vtempest/GRAB-API"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/grab-api.cjs.js",
|
|
13
|
+
"types": "./dist/grab-api.d.ts",
|
|
14
|
+
"module": "./dist/grab-api.es.js",
|
|
15
|
+
"bin": {
|
|
16
|
+
"grab": "./src/grab-url.js",
|
|
17
|
+
"grab-url": "./src/grab-url.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/grab-api.d.ts",
|
|
22
|
+
"import": "./dist/grab-api.es.js",
|
|
23
|
+
"require": "./dist/grab-api.cjs.js"
|
|
24
|
+
},
|
|
25
|
+
"./icons": {
|
|
26
|
+
"types": "./dist/icons.d.ts",
|
|
27
|
+
"import": "./dist/icons.es.js",
|
|
28
|
+
"require": "./dist/icons.cjs.js"
|
|
29
|
+
},
|
|
30
|
+
"./icons/*": {
|
|
31
|
+
"types": "./dist/*.d.ts",
|
|
32
|
+
"import": "./dist/*.js",
|
|
33
|
+
"require": "./dist/*.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"src",
|
|
39
|
+
"src/grab-cli.js",
|
|
40
|
+
"src/grab-url-cli.js",
|
|
41
|
+
"src/icons/cli/spinners.json"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"down": "bun test command.test.js",
|
|
45
|
+
"make": "npm run make:icons; npm run make:docs; npm run make:main",
|
|
46
|
+
"make:docs": "cd docs-config && npm run make:docs",
|
|
47
|
+
"make:icons": "npx export-svg-typescript@latest -i ./src/icons -o ./src/icons/index.ts",
|
|
48
|
+
"make:main": "vite build",
|
|
49
|
+
"ship": "npx standard-version --release-as patch; npm publish",
|
|
50
|
+
"check": "vitest --ui",
|
|
51
|
+
"docs": "cd docs-config && npm run docs"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@vitest/ui": "^3.1.4",
|
|
55
|
+
"export-svg-typescript": "^0.1.6",
|
|
56
|
+
"terser": "^5.40.0",
|
|
57
|
+
"typescript": "^5.8.3",
|
|
58
|
+
"vite": "^6.3.5",
|
|
59
|
+
"vite-plugin-dts": "^4.5.4",
|
|
60
|
+
"vitest": "^3.1.4"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"api",
|
|
64
|
+
"axios",
|
|
65
|
+
"request",
|
|
66
|
+
"browser",
|
|
67
|
+
"tanstack",
|
|
68
|
+
"query",
|
|
69
|
+
"post",
|
|
70
|
+
"mock-api",
|
|
71
|
+
"fetch",
|
|
72
|
+
"http"
|
|
73
|
+
],
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@types/node": "^24.2.1",
|
|
76
|
+
"chalk": "^5.4.1",
|
|
77
|
+
"cli-progress": "^3.12.0",
|
|
78
|
+
"cli-spinners": "^3.2.0",
|
|
79
|
+
"cli-table3": "^0.6.5",
|
|
80
|
+
"node-global-key-listener": "^0.3.0",
|
|
81
|
+
"ora": "^8.2.0"
|
|
82
|
+
}
|
|
83
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
|
|
2
|
+
<p align="center">
|
|
3
|
+
<img width="400px" src="https://i.imgur.com/qrQWkeb.png" />
|
|
4
|
+
</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<br />
|
|
7
|
+
<a href="https://npmjs.org/package/grab-api.js">
|
|
8
|
+
<img src="https://i.imgur.com/ifE8SbX.png"
|
|
9
|
+
alt="NPM badge" />
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://discord.gg/SJdBqBz3tV"><img src="https://img.shields.io/discord/1110227955554209923.svg?label=Chat&logo=Discord&colorB=7289da&style=flat" alt="Join Discord" /></a>
|
|
14
|
+
<a href="https://github.com/vtempest/grab-api/discussions">
|
|
15
|
+
<img alt="GitHub Stars" src="https://img.shields.io/github/stars/vtempest/grab-api" /></a>
|
|
16
|
+
<a href="https://npmjs.org/package/grab-api.js"><img alt="NPM Version" src="https://img.shields.io/npm/v/grab-api.js" /></a>
|
|
17
|
+
<a href="https://bundlephobia.com/package/grab-api.js"><img src="https://img.shields.io/bundlephobia/minzip/grab-api.js" /></a>
|
|
18
|
+
<a href="https://github.com/vtempest/grab-API/discussions"><img alt="GitHub Discussions"
|
|
19
|
+
src="https://img.shields.io/github/discussions/vtempest/grab-API" /></a>
|
|
20
|
+
<a href="https://github.blog/developer-skills/github/beginners-guide-to-github-creating-a-pull-request/"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome"/></a>
|
|
21
|
+
<a href="https://codespaces.new/vtempest/grab-API"><img src="https://github.com/codespaces/badge.svg" width="150" height="20"/></a>
|
|
22
|
+
</p>
|
|
23
|
+
<h3 align="center">
|
|
24
|
+
<a href="https://grab.js.org"> 📑 Docs (grab.js.org)</a>
|
|
25
|
+
<a href="https://grab.js.org/guide/Examples"> 🎯 Example Strategies </a>
|
|
26
|
+
</h3>
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
npm i grab-api.js
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### GRAB: Generate Request to API from Browser
|
|
33
|
+
|
|
34
|
+
1. **GRAB is the FBEST Request Manager: Functionally Brilliant, Elegantly Simple Tool**: One Function, no dependencies, minimalist syntax, [more features than alternatives](https://grab.js.org/guide/Comparisons)
|
|
35
|
+
2. **Auto-JSON Convert**: Pass parameters and get response or error in JSON, handling other data types as is.
|
|
36
|
+
3. **isLoading Status**: Sets `.isLoading=true` on the pre-initialized response object so you can show a "Loading..." in any framework
|
|
37
|
+
4. **Debug Logging**: Adds global `log()` and prints colored JSON structure, response, timing for requests in test.
|
|
38
|
+
5. **Mock Server Support**: Configure `window.grab.mock` for development and testing environments
|
|
39
|
+
6. **Cancel Duplicates**: Prevent this request if one is ongoing to same path & params, or cancel the ongoing request.
|
|
40
|
+
7. **Timeout & Retry**: Customizable request timeout, default 30s, and auto-retry on error
|
|
41
|
+
8. **DevTools**: `Ctrl+I` overlays webpage with devtools showing all requests and responses, timing, and JSON structure.
|
|
42
|
+
9. **Request History**: Stores all request and response data in global `grab.log` object
|
|
43
|
+
10. **Pagination Infinite Scroll**: Built-in pagination for infinite scroll to auto-load and merge next result page, with scroll position recovery.
|
|
44
|
+
11. **Base URL Based on Environment**: Configure `grab.defaults.baseURL` once at the top, overide with `SERVER_API_URL` in `.env`.
|
|
45
|
+
12. **Frontend Cache**: Set cache headers and retrieve from frontend memory for repeat requests to static data.
|
|
46
|
+
13. **Regrab On Error**: Regrab on timeout error, or on window refocus, or on network change, or on stale data.
|
|
47
|
+
14. **Framework Agnostic**: Alternatives like TanStack work only in component initialization and depend on React & others.
|
|
48
|
+
15. **Globals**: Adds to window in browser or global in Node.js so you only import once: `grab()`, `log()`, `grab.log`, `grab.mock`, `grab.defaults`
|
|
49
|
+
16. **TypeScript Tooltips**: Developers can hover over option names and autocomplete TypeScript.
|
|
50
|
+
17. **Request Stategies**: [🎯 Examples](https://grab.js.org/guide/Examples) show common stategies like debounce, repeat, proxy, unit tests, interceptors, file upload, etc
|
|
51
|
+
18. **Rate Limiting**: Built-in rate limiting to prevent multi-click cascading responses, require to wait seconds between requests.
|
|
52
|
+
19. **Repeat**: Repeat request this many times, or repeat every X seconds to poll for updates.
|
|
53
|
+
20. **Loading Icons**: Import from `grab-api.js/icons` to get enhanced animated loading icons.
|
|
54
|
+
|
|
55
|
+
### Examples
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import grab from 'grab-api.js';
|
|
59
|
+
|
|
60
|
+
let res = $state({}) as {
|
|
61
|
+
results: Array<{title:string}>,
|
|
62
|
+
isLoading: boolean,
|
|
63
|
+
error: string,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
await grab('search', {
|
|
67
|
+
response: res,
|
|
68
|
+
query: "search words",
|
|
69
|
+
post: true
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
grab('user').then(log)
|
|
73
|
+
|
|
74
|
+
//in svelte component
|
|
75
|
+
{#if res.results}
|
|
76
|
+
{res.results}
|
|
77
|
+
{:else if res.isLoading}
|
|
78
|
+
...
|
|
79
|
+
{:else if res.error}
|
|
80
|
+
{res.error}
|
|
81
|
+
{/if}
|
|
82
|
+
|
|
83
|
+
//Setup Mock testing server, response is object or function
|
|
84
|
+
window.grab.mock["search"] = {
|
|
85
|
+
response: (params) => {
|
|
86
|
+
return { results: [{title:`Result about ${params.query}`}] };
|
|
87
|
+
},
|
|
88
|
+
method: "POST"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//set defaults for all requests
|
|
92
|
+
grab("", {
|
|
93
|
+
setDefaults: true,
|
|
94
|
+
baseURL: "http://localhost:8080",
|
|
95
|
+
timeout: 30,
|
|
96
|
+
debug: true,
|
|
97
|
+
rateLimit: 1,
|
|
98
|
+
cache: true,
|
|
99
|
+
cancelOngoingIfNew: true,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
grab.defaults.baseURL = "http://localhost:8080/api/";
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Screenshots
|
|
106
|
+
|
|
107
|
+
**Animated SVG Loading Icons with Customizable Colors**
|
|
108
|
+
|
|
109
|
+

|
|
110
|
+
|
|
111
|
+
**Set Types for Tooltips on Request & Response**
|
|
112
|
+
|
|
113
|
+

|
|
114
|
+
|
|
115
|
+
**Debug Colorized log(JSON)**
|
|
116
|
+
|
|
117
|
+

|
|
118
|
+
|
|
119
|
+
**Autocomplete option names**
|
|
120
|
+
|
|
121
|
+

|
|
122
|
+
|
|
123
|
+
**Hover over options for info**
|
|
124
|
+
|
|
125
|
+

|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### Comparison of HTTP Request Libraries
|
|
129
|
+
|
|
130
|
+
| Feature | [GRAB](https://github.com/vtempest/grab-api) | [Axios](https://github.com/axios/axios) | [TanStack Query](https://github.com/TanStack/query) | [SWR](https://github.com/vercel/swr) | [Alova](https://github.com/alovajs/alova) | [SuperAgent](https://github.com/ladjs/superagent) | [Apisauce](https://github.com/infinitered/apisauce) | [Ky](https://github.com/sindresorhus/ky) |
|
|
131
|
+
| :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- |
|
|
132
|
+
| Size | ✅ 3KB | ❌ 13KB | ❌ 39KB | ❌ 4.2KB | ⚠️ 4KB | ❌ 19KB | ❌ 15KB (with axios) | ⚠️ 4KB |
|
|
133
|
+
| Zero Dependencies | ✅ Yes | ❌ No | ❌ No | ❌ No | ✅ Yes | ❌ No | ❌ Needs Axios | ✅ Yes |
|
|
134
|
+
| isLoading State Handling | ✅ Auto-managed | ❌ Manual | ✅ Yes | ✅ Yes | ✅ Yes | ❌ Manual | ❌ Manual | ❌ Manual |
|
|
135
|
+
| Auto JSON Handling | ✅ Automatic | ✅ Configurable | ❌ Manual | ❌ Manual | ✅ Automatic | ✅ Automatic | ✅ Automatic | ✅ Automatic |
|
|
136
|
+
| Request Deduplication | ✅ Built-in | ❌ No | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ❌ No |
|
|
137
|
+
| Caching | ✅ Multi-level | ❌ No | ✅ Advanced | ✅ Advanced | ✅ Multi-level | ❌ No | ❌ No | ❌ No |
|
|
138
|
+
| Mock Testing | ✅ Easy setup | ❌ Needs MSW/etc | ❌ Needs MSW/etc | ❌ Needs MSW/etc | ⚠️ Basic | ❌ Needs separate lib | ❌ Needs separate lib | ❌ Needs MSW/etc |
|
|
139
|
+
| Rate Limiting | ✅ Built-in | ❌ Manual | ❌ Manual | ❌ Manual | ⚠️ Basic | ❌ Manual | ❌ Manual | ❌ Manual |
|
|
140
|
+
| Automatic Retry | ✅ Configurable | ⚠️ Via interceptors | ✅ Built-in | ✅ Built-in | ✅ Built-in | ✅ Built-in | ❌ Manual | ✅ Built-in |
|
|
141
|
+
| Request Cancellation | ✅ Auto + manual | ✅ Manual | ✅ Automatic | ✅ Automatic | ✅ Manual | ✅ Manual | ✅ Manual | ✅ Manual |
|
|
142
|
+
| Pagination Support | ✅ Infinite scroll | ❌ Manual | ✅ Advanced | ⚠️ Basic | ✅ Built-in | ❌ Manual | ❌ Manual | ❌ Manual |
|
|
143
|
+
| Interceptors | ✅ Advanced | ✅ Advanced | ⚠️ Limited | ⚠️ Limited | ✅ Advanced | ✅ Plugins | ✅ Transforms | ✅ Hooks system |
|
|
144
|
+
| Debug Logging | ✅ Colored output | ⚠️ Basic | ✅ DevTools | ✅ DevTools | ⚠️ Basic | ⚠️ Basic | ⚠️ Basic | ⚠️ Basic |
|
|
145
|
+
| Request History | ✅ Built-in | ❌ Manual | ✅ DevTools | ✅ DevTools | ❌ Manual | ❌ Manual | ❌ Manual | ❌ Manual |
|
|
146
|
+
| Easy Syntax | ✅ Minimal | ⚠️ Medium | ❌ High | ❌ High | ⚠️ Medium | ⚠️ Medium | ✅ Low | ✅ Minimal |
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
**Stop trying to make fetch happen!** [*](https://knowyourmeme.com/memes/stop-trying-to-make-fetch-happen)
|
|
150
|
+
|
|
151
|
+
**Why fetch things when you can just GRAB?**
|
|
152
|
+
|
|
153
|
+
**Debugging requests is a bitch. [Make the switch!](https://grab.js.org/guide/Comparisons)**
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
🌟 Star this repo so it will grow and get updates!
|