aziosxjs 0.2.0 → 0.4.0
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 +128 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,39 +1,58 @@
|
|
|
1
1
|
# Aziosxjs
|
|
2
2
|
|
|
3
|
-
A lightweight HTTP client for Node.js
|
|
3
|
+
A modern, lightweight HTTP client for Node.js designed for performance, extensibility, and clarity.
|
|
4
4
|
|
|
5
|
-
Aziosxjs provides a clean
|
|
5
|
+
Aziosxjs provides a clean API for making HTTP requests while exposing a modular request pipeline architecture.
|
|
6
|
+
It is built directly on Node.js low-level `http` and `https` modules to demonstrate how production-grade HTTP clients work internally.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
The goal of this project is to provide a simple but powerful HTTP client that supports advanced features such as retries, caching, request deduplication, and rate limiting.
|
|
8
9
|
|
|
9
10
|
---
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
# Features
|
|
13
|
+
|
|
14
|
+
### Core HTTP
|
|
12
15
|
|
|
13
|
-
* Simple and clean API
|
|
14
16
|
* Promise-based HTTP requests
|
|
15
|
-
*
|
|
16
|
-
* Request and response interceptors
|
|
17
|
-
* Structured error system
|
|
18
|
-
* Request cancellation support
|
|
19
|
-
* Query parameter serialization
|
|
17
|
+
* Support for GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
|
|
20
18
|
* Automatic JSON parsing
|
|
19
|
+
* Automatic request body serialization
|
|
20
|
+
* Query parameter serialization
|
|
21
|
+
|
|
22
|
+
### Request Pipeline
|
|
23
|
+
|
|
24
|
+
* Request interceptors
|
|
25
|
+
* Response interceptors
|
|
26
|
+
* Structured error system
|
|
27
|
+
* AbortController cancellation support
|
|
28
|
+
|
|
29
|
+
### Performance Features
|
|
30
|
+
|
|
31
|
+
* Automatic retry system
|
|
32
|
+
* Exponential backoff strategy
|
|
33
|
+
* Request deduplication (prevents duplicate concurrent requests)
|
|
34
|
+
* Response caching
|
|
35
|
+
* Built-in rate limiting
|
|
36
|
+
|
|
37
|
+
### Developer Experience
|
|
38
|
+
|
|
21
39
|
* TypeScript support
|
|
22
40
|
* Modular architecture
|
|
41
|
+
* Lightweight dependency-free implementation
|
|
23
42
|
|
|
24
43
|
---
|
|
25
44
|
|
|
26
|
-
|
|
45
|
+
# Installation
|
|
27
46
|
|
|
28
|
-
```bash
|
|
47
|
+
```bash id="x0c2qz"
|
|
29
48
|
npm install aziosxjs
|
|
30
49
|
```
|
|
31
50
|
|
|
32
51
|
---
|
|
33
52
|
|
|
34
|
-
|
|
53
|
+
# Quick Example
|
|
35
54
|
|
|
36
|
-
```javascript
|
|
55
|
+
```javascript id="xgqz2e"
|
|
37
56
|
import azios from "aziosxjs";
|
|
38
57
|
|
|
39
58
|
async function getUsers() {
|
|
@@ -53,7 +72,7 @@ getUsers();
|
|
|
53
72
|
|
|
54
73
|
## GET Request
|
|
55
74
|
|
|
56
|
-
```javascript
|
|
75
|
+
```javascript id="q2s48a"
|
|
57
76
|
const res = await azios.get("https://api.example.com/users");
|
|
58
77
|
|
|
59
78
|
console.log(res.data);
|
|
@@ -63,7 +82,7 @@ console.log(res.data);
|
|
|
63
82
|
|
|
64
83
|
## POST Request
|
|
65
84
|
|
|
66
|
-
```javascript
|
|
85
|
+
```javascript id="ys8fr0"
|
|
67
86
|
const res = await azios.post(
|
|
68
87
|
"https://api.example.com/login",
|
|
69
88
|
{
|
|
@@ -79,9 +98,9 @@ console.log(res.data);
|
|
|
79
98
|
|
|
80
99
|
# Query Parameters
|
|
81
100
|
|
|
82
|
-
|
|
101
|
+
Aziosxjs automatically serializes query parameters.
|
|
83
102
|
|
|
84
|
-
```javascript
|
|
103
|
+
```javascript id="6e6w1q"
|
|
85
104
|
const res = await azios.get(
|
|
86
105
|
"https://jsonplaceholder.typicode.com/posts",
|
|
87
106
|
{
|
|
@@ -94,7 +113,7 @@ console.log(res.data);
|
|
|
94
113
|
|
|
95
114
|
Generated URL:
|
|
96
115
|
|
|
97
|
-
```
|
|
116
|
+
```id="2dq3rc"
|
|
98
117
|
/posts?_limit=2
|
|
99
118
|
```
|
|
100
119
|
|
|
@@ -106,12 +125,12 @@ Interceptors allow you to modify requests or responses globally.
|
|
|
106
125
|
|
|
107
126
|
## Request Interceptor
|
|
108
127
|
|
|
109
|
-
```javascript
|
|
128
|
+
```javascript id="o7j8rz"
|
|
110
129
|
azios.interceptors.request.use(config => {
|
|
111
130
|
console.log("Request intercepted");
|
|
112
131
|
|
|
113
132
|
if (!config.headers) config.headers = {};
|
|
114
|
-
config.headers["x-
|
|
133
|
+
config.headers["x-client"] = "aziosxjs";
|
|
115
134
|
|
|
116
135
|
return config;
|
|
117
136
|
});
|
|
@@ -121,7 +140,7 @@ azios.interceptors.request.use(config => {
|
|
|
121
140
|
|
|
122
141
|
## Response Interceptor
|
|
123
142
|
|
|
124
|
-
```javascript
|
|
143
|
+
```javascript id="w7r0uj"
|
|
125
144
|
azios.interceptors.response.use(response => {
|
|
126
145
|
console.log("Response intercepted");
|
|
127
146
|
return response;
|
|
@@ -132,9 +151,9 @@ azios.interceptors.response.use(response => {
|
|
|
132
151
|
|
|
133
152
|
# Request Cancellation
|
|
134
153
|
|
|
135
|
-
|
|
154
|
+
Requests can be cancelled using `AbortController`.
|
|
136
155
|
|
|
137
|
-
```javascript
|
|
156
|
+
```javascript id="68f4s3"
|
|
138
157
|
const controller = new AbortController();
|
|
139
158
|
|
|
140
159
|
azios.get(
|
|
@@ -145,45 +164,93 @@ azios.get(
|
|
|
145
164
|
controller.abort();
|
|
146
165
|
```
|
|
147
166
|
|
|
148
|
-
|
|
167
|
+
If aborted, Aziosxjs throws an error with code:
|
|
149
168
|
|
|
150
|
-
```
|
|
169
|
+
```id="m5ktg3"
|
|
151
170
|
ABORTED
|
|
152
171
|
```
|
|
153
172
|
|
|
154
173
|
---
|
|
155
174
|
|
|
175
|
+
# Retry System
|
|
176
|
+
|
|
177
|
+
Aziosxjs can automatically retry failed requests.
|
|
178
|
+
|
|
179
|
+
```javascript id="zwdg7p"
|
|
180
|
+
await azios.get("https://api.example.com/users", {
|
|
181
|
+
retry: 3
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Retries use **exponential backoff** to avoid overwhelming servers.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
# Response Caching
|
|
190
|
+
|
|
191
|
+
Responses can be cached in memory.
|
|
192
|
+
|
|
193
|
+
```javascript id="hjbrgx"
|
|
194
|
+
await azios.get(
|
|
195
|
+
"https://api.example.com/users",
|
|
196
|
+
{ cache: true }
|
|
197
|
+
);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Subsequent requests may return cached responses instantly.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
# Rate Limiting
|
|
205
|
+
|
|
206
|
+
Control the number of concurrent requests.
|
|
207
|
+
|
|
208
|
+
```javascript id="m2l4x9"
|
|
209
|
+
await azios.get(
|
|
210
|
+
"https://api.example.com/users",
|
|
211
|
+
{ rateLimit: 3 }
|
|
212
|
+
);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Only 3 requests will execute simultaneously.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
156
219
|
# Error Handling
|
|
157
220
|
|
|
158
|
-
|
|
221
|
+
Aziosxjs returns standardized error objects.
|
|
159
222
|
|
|
160
|
-
```javascript
|
|
223
|
+
```javascript id="n2d3kr"
|
|
161
224
|
try {
|
|
162
|
-
await azios.get("https://
|
|
225
|
+
await azios.get("https://invalid-url.test");
|
|
163
226
|
} catch (error) {
|
|
164
|
-
console.log(error.name);
|
|
165
|
-
console.log(error.code);
|
|
227
|
+
console.log(error.name); // AziosError
|
|
228
|
+
console.log(error.code); // NETWORK_ERROR
|
|
166
229
|
}
|
|
167
230
|
```
|
|
168
231
|
|
|
169
|
-
|
|
232
|
+
This makes debugging significantly easier.
|
|
170
233
|
|
|
171
234
|
---
|
|
172
235
|
|
|
173
|
-
# Architecture
|
|
236
|
+
# Request Pipeline Architecture
|
|
174
237
|
|
|
175
|
-
|
|
238
|
+
Aziosxjs follows a modular pipeline design.
|
|
176
239
|
|
|
177
|
-
```
|
|
240
|
+
```id="m2b3ux"
|
|
178
241
|
User Code
|
|
179
242
|
↓
|
|
180
243
|
Azios Instance
|
|
181
244
|
↓
|
|
182
245
|
Request Interceptors
|
|
183
246
|
↓
|
|
247
|
+
Retry Engine
|
|
248
|
+
↓
|
|
249
|
+
Rate Limiter
|
|
250
|
+
↓
|
|
184
251
|
dispatchRequest (HTTP engine)
|
|
185
252
|
↓
|
|
186
|
-
Node.js http/https
|
|
253
|
+
Node.js http / https
|
|
187
254
|
↓
|
|
188
255
|
Response Interceptors
|
|
189
256
|
↓
|
|
@@ -194,12 +261,19 @@ Return Response
|
|
|
194
261
|
|
|
195
262
|
# Project Structure
|
|
196
263
|
|
|
197
|
-
```
|
|
264
|
+
```id="v2z3go"
|
|
198
265
|
src
|
|
199
266
|
├── core
|
|
200
267
|
│ ├── Azios.ts
|
|
201
268
|
│ ├── createInstance.ts
|
|
202
|
-
│
|
|
269
|
+
│ ├── dispatchRequest.ts
|
|
270
|
+
│ └── requestStore.ts
|
|
271
|
+
│
|
|
272
|
+
├── cache
|
|
273
|
+
│ └── memoryCache.ts
|
|
274
|
+
│
|
|
275
|
+
├── rateLimiter
|
|
276
|
+
│ └── rateLimiter.ts
|
|
203
277
|
│
|
|
204
278
|
├── interceptors
|
|
205
279
|
│ └── InterceptorManager.ts
|
|
@@ -222,30 +296,37 @@ src
|
|
|
222
296
|
|
|
223
297
|
# Version Roadmap
|
|
224
298
|
|
|
225
|
-
|
|
299
|
+
### v0.1
|
|
226
300
|
|
|
227
301
|
* Core HTTP client
|
|
228
302
|
* Instances
|
|
229
303
|
* JSON handling
|
|
230
|
-
*
|
|
304
|
+
* Request configuration
|
|
231
305
|
|
|
232
|
-
|
|
306
|
+
### v0.2
|
|
233
307
|
|
|
234
308
|
* Interceptor pipeline
|
|
235
309
|
* Structured error system
|
|
236
310
|
* Request cancellation
|
|
237
|
-
* Query parameter
|
|
238
|
-
|
|
239
|
-
## Upcoming
|
|
311
|
+
* Query parameter serialization
|
|
240
312
|
|
|
241
|
-
|
|
313
|
+
### v0.3
|
|
242
314
|
|
|
243
315
|
* Retry mechanism
|
|
316
|
+
* Exponential backoff
|
|
244
317
|
* Request deduplication
|
|
245
|
-
|
|
318
|
+
|
|
319
|
+
### v0.4
|
|
320
|
+
|
|
321
|
+
* Response caching
|
|
246
322
|
* Rate limiting
|
|
323
|
+
|
|
324
|
+
### Planned
|
|
325
|
+
|
|
247
326
|
* Plugin system
|
|
248
|
-
* Middleware
|
|
327
|
+
* Middleware pipeline
|
|
328
|
+
* Advanced TypeScript inference
|
|
329
|
+
* Universal runtime support (Node, Browser, Edge)
|
|
249
330
|
|
|
250
331
|
---
|
|
251
332
|
|
|
@@ -253,8 +334,6 @@ Future improvements planned:
|
|
|
253
334
|
|
|
254
335
|
Contributions are welcome.
|
|
255
336
|
|
|
256
|
-
If you'd like to improve Aziosxjs:
|
|
257
|
-
|
|
258
337
|
1. Fork the repository
|
|
259
338
|
2. Create a feature branch
|
|
260
339
|
3. Submit a pull request
|