hyperttp 0.1.9 → 0.2.1
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 +55 -65
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts +64 -287
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts.map +1 -1
- package/dist/Hyperttp/Core/HttpClientImproved.js +258 -755
- package/dist/Hyperttp/Core/HttpClientImproved.js.map +1 -1
- package/dist/Hyperttp/Core/RequestBuilder.d.ts +97 -0
- package/dist/Hyperttp/Core/RequestBuilder.d.ts.map +1 -0
- package/dist/Hyperttp/Core/RequestBuilder.js +174 -0
- package/dist/Hyperttp/Core/RequestBuilder.js.map +1 -0
- package/dist/Hyperttp/Core/index.d.ts +1 -0
- package/dist/Hyperttp/Core/index.d.ts.map +1 -1
- package/dist/Hyperttp/Core/index.js +3 -1
- package/dist/Hyperttp/Core/index.js.map +1 -1
- package/dist/Hyperttp/index.d.ts +1 -1
- package/dist/Hyperttp/index.d.ts.map +1 -1
- package/dist/Hyperttp/index.js +2 -1
- package/dist/Hyperttp/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,48 +1,29 @@
|
|
|
1
1
|
# Hyperttp
|
|
2
2
|
|
|
3
|
-
Advanced HTTP client for Node.js with caching, rate limiting, request queuing, automatic retries, cookie management, and
|
|
3
|
+
Advanced HTTP client for Node.js with caching, rate limiting, request queuing, automatic retries, cookie management, and automatic JSON/XML parsing.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
- Automatic request deduplication
|
|
8
|
+
- LRU caching with TTL
|
|
9
|
+
- Configurable rate limiting
|
|
10
|
+
- Concurrent request management
|
|
11
|
+
- Exponential backoff with jitter for retries
|
|
12
|
+
- Cookie jar support
|
|
13
|
+
- Automatic response parsing (JSON/XML/text/buffer)
|
|
14
|
+
- Automatic handling of redirects
|
|
15
|
+
- Fluent request builder API
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
## Installation
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Russian Version
|
|
25
|
-
|
|
26
|
-
### Описание
|
|
27
|
-
|
|
28
|
-
Расширенный HTTP клиент для Node.js с кэшированием, ограничением запросов, очередями запросов, автоматическими повторными попытками, управлением cookie и декомпрессией ответов.
|
|
29
|
-
|
|
30
|
-
### Возможности
|
|
31
|
-
|
|
32
|
-
* Автоматическое предотвращение дублирования запросов
|
|
33
|
-
* LRU кэширование с TTL
|
|
34
|
-
* Настраиваемое ограничение запросов
|
|
35
|
-
* Управление конкурентными запросами
|
|
36
|
-
* Экспоненциальная задержка с джиттером
|
|
37
|
-
* Поддержка cookie jar
|
|
38
|
-
* Автопарсинг JSON/XML
|
|
39
|
-
* Поддержка сжатия (gzip, deflate, brotli)
|
|
19
|
+
```bash
|
|
20
|
+
npm install hyperttp
|
|
21
|
+
```
|
|
40
22
|
|
|
41
|
-
|
|
23
|
+
## Basic Usage
|
|
42
24
|
|
|
43
|
-
```
|
|
44
|
-
import HttpClientImproved from
|
|
45
|
-
import Request from './src/Hyperttp/Request';
|
|
25
|
+
```typescript
|
|
26
|
+
import HttpClientImproved from "hyperttp";
|
|
46
27
|
|
|
47
28
|
const client = new HttpClientImproved({
|
|
48
29
|
timeout: 10000,
|
|
@@ -50,43 +31,52 @@ const client = new HttpClientImproved({
|
|
|
50
31
|
logger: (level, msg) => console.log(`[${level}] ${msg}`),
|
|
51
32
|
});
|
|
52
33
|
|
|
53
|
-
|
|
54
|
-
const data = await client.get(
|
|
34
|
+
// Simple GET request
|
|
35
|
+
const data = await client.get("https://api.example.com/data");
|
|
55
36
|
console.log(data);
|
|
56
|
-
```
|
|
57
37
|
|
|
58
|
-
|
|
38
|
+
// POST request with JSON body
|
|
39
|
+
const postData = await client.post("https://api.example.com/items", {
|
|
40
|
+
name: "Item 1",
|
|
41
|
+
});
|
|
42
|
+
console.log(postData);
|
|
59
43
|
|
|
60
|
-
|
|
44
|
+
// Using fluent RequestBuilder
|
|
45
|
+
const builderData = await client
|
|
46
|
+
.request("https://api.example.com/search")
|
|
47
|
+
.query({ q: "hyperttp", limit: 10 })
|
|
48
|
+
.headers({ Authorization: "Bearer TOKEN" })
|
|
49
|
+
.json()
|
|
50
|
+
.send();
|
|
61
51
|
|
|
62
|
-
|
|
52
|
+
console.log(builderData);
|
|
53
|
+
```
|
|
63
54
|
|
|
64
|
-
|
|
55
|
+
## Fluent Builder API
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
client
|
|
59
|
+
.request("https://api.example.com/data")
|
|
60
|
+
.get() // default
|
|
61
|
+
.headers({ "X-Test": "123" })
|
|
62
|
+
.query({ page: 1 })
|
|
63
|
+
.json() // or .text(), .xml()
|
|
64
|
+
.send()
|
|
65
|
+
.then(console.log);
|
|
66
|
+
```
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
## Advanced Features
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
* LRU caching with TTL
|
|
70
|
-
* Configurable rate limiting
|
|
71
|
-
* Concurrent request management
|
|
72
|
-
* Exponential backoff with jitter
|
|
73
|
-
* Cookie jar support
|
|
74
|
-
* Automatic response parsing (JSON/XML)
|
|
75
|
-
* Compression support (gzip, deflate, brotli)
|
|
70
|
+
- Caching: Automatically caches GET/HEAD responses, configurable TTL and max size
|
|
76
71
|
|
|
77
|
-
|
|
72
|
+
- Rate limiting: Prevents overwhelming servers
|
|
78
73
|
|
|
79
|
-
|
|
80
|
-
import HttpClientImproved from './src/Hyperttp/Core/HttpClientImproved';
|
|
81
|
-
import Request from './src/Hyperttp/Request';
|
|
74
|
+
- Retries: Automatic retries for 408, 429, 500, 502, 503, 504 with exponential backoff
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
timeout: 10000,
|
|
85
|
-
maxConcurrent: 10,
|
|
86
|
-
logger: (level, msg) => console.log(`[${level}] ${msg}`),
|
|
87
|
-
});
|
|
76
|
+
- Cookies: Persistent cookie jar per client
|
|
88
77
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
- Metrics: Track request timings, bytes sent/received, retries, and cache hits
|
|
79
|
+
|
|
80
|
+
## Documentation
|
|
81
|
+
|
|
82
|
+
- [Русский](https://github.com/Dirold2/hyperttp/blob/main/lang/ru/README.md)
|
|
@@ -1,57 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CookieJar } from "tough-cookie";
|
|
2
|
+
import { HttpClientInterface, HttpClientOptions, RequestInterceptor, RequestInterface, RequestMetrics, ResponseInterceptor, ResponseType, StreamResponse } from "../../Types";
|
|
3
|
+
import { RequestBuilder } from "./RequestBuilder";
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Предоставляет надежный интерфейс для выполнения HTTP-запросов с автоматической обработкой
|
|
6
|
-
* распространенных паттернов, таких как повторные попытки, кэширование и перехват запросов/ответов.
|
|
7
|
-
* @en
|
|
8
|
-
* Enhanced HTTP client with caching, rate limiting, retry logic, and advanced features.
|
|
9
|
-
* Provides a robust interface for making HTTP requests with automatic handling of
|
|
10
|
-
* common patterns like retries, caching, and request/response interception.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const client = new HttpClientImproved({
|
|
15
|
-
* timeout: 10000,
|
|
16
|
-
* maxRetries: 3,
|
|
17
|
-
* cacheTTL: 300000,
|
|
18
|
-
* rateLimit: { maxRequests: 100, windowMs: 60000 }
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* const response = await client.get('https://api.example.com/data');
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* // Using the fluent request builder
|
|
27
|
-
* const client = new HttpClientImproved();
|
|
28
|
-
* const response = await client.request('https://api.example.com/data')
|
|
29
|
-
* .headers({ 'Authorization': 'Bearer token' })
|
|
30
|
-
* .json()
|
|
31
|
-
* .send();
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* // Using RequestInterface for complex requests
|
|
37
|
-
* import { RequestInterface } from './src';
|
|
38
|
-
*
|
|
39
|
-
* class ApiRequest implements RequestInterface {
|
|
40
|
-
* constructor(
|
|
41
|
-
* private url: string,
|
|
42
|
-
* private headers: Record<string, string> = {},
|
|
43
|
-
* private body?: any
|
|
44
|
-
* ) {}
|
|
45
|
-
*
|
|
46
|
-
* getURL(): string { return this.url; }
|
|
47
|
-
* getHeaders(): Record<string, string> { return this.headers; }
|
|
48
|
-
* getBodyData(): any { return this.body; }
|
|
49
|
-
* }
|
|
50
|
-
*
|
|
51
|
-
* const client = new HttpClientImproved();
|
|
52
|
-
* const request = new ApiRequest('https://api.example.com/data');
|
|
53
|
-
* const response = await client.get(request);
|
|
54
|
-
* ```
|
|
5
|
+
* Advanced HTTP client with built-in caching, rate limiting, request queuing,
|
|
6
|
+
* automatic retries, cookie management, and response decompression.
|
|
55
7
|
*/
|
|
56
8
|
export default class HttpClientImproved implements HttpClientInterface {
|
|
57
9
|
private cookieJar;
|
|
@@ -61,184 +13,108 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
61
13
|
private limiter?;
|
|
62
14
|
private inflight;
|
|
63
15
|
private retryOptions;
|
|
64
|
-
private
|
|
16
|
+
private defaultHeaders;
|
|
65
17
|
private options;
|
|
66
18
|
private requestInterceptors;
|
|
67
19
|
private responseInterceptors;
|
|
68
20
|
private requestMetrics;
|
|
69
|
-
constructor(options?: HttpClientOptions);
|
|
70
|
-
private log;
|
|
71
21
|
/**
|
|
72
|
-
* Creates a
|
|
73
|
-
* @param
|
|
74
|
-
* @returns SHA1 hash of the body, truncated to 8 characters
|
|
22
|
+
* Creates a new instance of HttpClientImproved.
|
|
23
|
+
* @param options Optional configuration options for the HTTP client
|
|
75
24
|
*/
|
|
76
|
-
|
|
25
|
+
constructor(options?: HttpClientOptions);
|
|
77
26
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
80
|
-
* @returns Delay in milliseconds
|
|
27
|
+
* Sets default headers that will be applied to all outgoing requests.
|
|
28
|
+
* @param headers An object containing header names and values
|
|
81
29
|
*/
|
|
82
|
-
|
|
30
|
+
setDefaultHeaders(headers: Record<string, string>): void;
|
|
83
31
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
86
|
-
* @returns Promise that resolves after the delay
|
|
32
|
+
* Returns the cookie jar used for managing HTTP cookies.
|
|
33
|
+
* @returns The CookieJar instance
|
|
87
34
|
*/
|
|
88
|
-
|
|
35
|
+
getCookieJar(): CookieJar;
|
|
89
36
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @param config - Original request configuration
|
|
93
|
-
* @returns Modified request configuration
|
|
37
|
+
* Adds a request interceptor to modify requests before they are sent.
|
|
38
|
+
* @param interceptor The interceptor function to add
|
|
94
39
|
*/
|
|
95
|
-
|
|
40
|
+
addRequestInterceptor(interceptor: RequestInterceptor): void;
|
|
96
41
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @param response - Original response data
|
|
100
|
-
* @returns Modified response data
|
|
42
|
+
* Adds a response interceptor to modify responses after they are received.
|
|
43
|
+
* @param interceptor The interceptor function to add
|
|
101
44
|
*/
|
|
45
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): void;
|
|
46
|
+
/** Closes the HTTP agent to properly terminate keep-alive connections. */
|
|
47
|
+
close(): void;
|
|
48
|
+
private log;
|
|
49
|
+
private decompress;
|
|
50
|
+
private calcDelay;
|
|
51
|
+
private sleep;
|
|
52
|
+
private applyRequestInterceptors;
|
|
102
53
|
private applyResponseInterceptors;
|
|
103
|
-
/**
|
|
104
|
-
* Resolves a redirect location relative to the base URL.
|
|
105
|
-
* Handles both absolute and relative redirect URLs.
|
|
106
|
-
* @param location - The redirect location from the response
|
|
107
|
-
* @param baseUrl - The original request URL
|
|
108
|
-
* @returns The resolved absolute URL
|
|
109
|
-
*/
|
|
110
54
|
private resolveRedirect;
|
|
111
|
-
/**
|
|
112
|
-
* Parses the Retry-After header to determine when to retry a request.
|
|
113
|
-
* Supports both seconds and HTTP date formats.
|
|
114
|
-
* @param retryAfterHeader - The Retry-After header value
|
|
115
|
-
* @returns Delay in milliseconds, or undefined if not parseable
|
|
116
|
-
*/
|
|
117
55
|
private parseRetryAfterMs;
|
|
118
|
-
/**
|
|
119
|
-
* Reads response body with size limit enforcement.
|
|
120
|
-
* Collects chunks until the response is complete or the limit is exceeded.
|
|
121
|
-
* @param body - Async iterable of response chunks
|
|
122
|
-
* @returns Complete response body as a Buffer
|
|
123
|
-
*/
|
|
124
56
|
private readBodyWithLimit;
|
|
125
|
-
/**
|
|
126
|
-
* Removes old metrics entries to prevent memory leaks.
|
|
127
|
-
* Keeps only metrics from the last 24 hours.
|
|
128
|
-
*/
|
|
129
|
-
private trimMetrics;
|
|
130
|
-
/**
|
|
131
|
-
* Sends an HTTP request with retry logic and rate limiting.
|
|
132
|
-
* Handles timeouts, redirects, and various retry scenarios.
|
|
133
|
-
* @param method - HTTP method (GET, POST, etc.)
|
|
134
|
-
* @param url - Target URL
|
|
135
|
-
* @param headers - HTTP headers
|
|
136
|
-
* @param body - Request body (optional)
|
|
137
|
-
* @param metrics - Optional metrics object to track request details
|
|
138
|
-
* @param redirects - Number of redirects followed so far
|
|
139
|
-
* @returns Promise resolving to the response data
|
|
140
|
-
*/
|
|
141
|
-
private sendOnce;
|
|
142
57
|
private sendWithRetry;
|
|
143
|
-
/**
|
|
144
|
-
* Parses the Content-Type header to extract MIME type and character encoding.
|
|
145
|
-
* @param contentType - Content-Type header value
|
|
146
|
-
* @returns Object containing type and charset information
|
|
147
|
-
*/
|
|
148
58
|
private parseContentType;
|
|
149
|
-
|
|
150
|
-
* Parses the HTTP response body based on content type and requested response type.
|
|
151
|
-
* Handles JSON, XML, text, and buffer responses with fallback parsing.
|
|
152
|
-
* @param res - HTTP response object
|
|
153
|
-
* @param responseType - Desired response type
|
|
154
|
-
* @returns Parsed response data
|
|
155
|
-
*/
|
|
59
|
+
private xmlParser;
|
|
156
60
|
private parseResponse;
|
|
157
|
-
/**
|
|
158
|
-
* Makes an HTTP request without using the cache.
|
|
159
|
-
* Used for methods that shouldn't be cached or when caching is disabled.
|
|
160
|
-
* @param method - HTTP method
|
|
161
|
-
* @param req - Request configuration
|
|
162
|
-
* @param responseType - Expected response type
|
|
163
|
-
* @returns Promise resolving to the response data
|
|
164
|
-
*/
|
|
165
|
-
private requestInternalWithoutCache;
|
|
166
|
-
/**
|
|
167
|
-
* Makes an HTTP request with caching support.
|
|
168
|
-
* Handles cache lookups, request deduplication, and automatic cache storage.
|
|
169
|
-
* @param method - HTTP method
|
|
170
|
-
* @param req - Request configuration
|
|
171
|
-
* @param useCache - Whether to use caching (default: true)
|
|
172
|
-
* @param responseType - Expected response type
|
|
173
|
-
* @returns Promise resolving to the response data
|
|
174
|
-
*/
|
|
175
|
-
private fastRequest;
|
|
176
61
|
private requestInternal;
|
|
177
62
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @
|
|
182
|
-
* @
|
|
183
|
-
* @returns Promise resolving to the response data
|
|
63
|
+
* Performs an HTTP GET request.
|
|
64
|
+
* @param req The request object containing URL and headers
|
|
65
|
+
* @param responseType Optional response parsing type
|
|
66
|
+
* @returns A promise that resolves to the parsed response
|
|
67
|
+
* @template T The expected response type
|
|
184
68
|
*/
|
|
185
69
|
get<T = any>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
186
70
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* @
|
|
191
|
-
* @
|
|
192
|
-
* @param responseType - Expected response type (default: "json")
|
|
193
|
-
* @returns Promise resolving to the response data
|
|
71
|
+
* Performs an HTTP POST request.
|
|
72
|
+
* @param req The request object containing URL, body, and headers
|
|
73
|
+
* @param responseType Optional response parsing type
|
|
74
|
+
* @returns A promise that resolves to the parsed response
|
|
75
|
+
* @template T The expected response type
|
|
194
76
|
*/
|
|
195
77
|
post<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
196
78
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* @
|
|
201
|
-
* @
|
|
202
|
-
* @param responseType - Expected response type (default: "json")
|
|
203
|
-
* @returns Promise resolving to the response data
|
|
79
|
+
* Performs an HTTP PUT request.
|
|
80
|
+
* @param req The request object containing URL, body, and headers
|
|
81
|
+
* @param responseType Optional response parsing type
|
|
82
|
+
* @returns A promise that resolves to the parsed response
|
|
83
|
+
* @template T The expected response type
|
|
204
84
|
*/
|
|
205
85
|
put<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
206
86
|
/**
|
|
207
|
-
*
|
|
208
|
-
* @
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
* Makes an HTTP DELETE request.
|
|
213
|
-
* Supports both RequestInterface objects and direct URL strings.
|
|
214
|
-
* DELETE requests are not cached by default due to their side effects.
|
|
215
|
-
* @param req - Request configuration or URL string
|
|
216
|
-
* @param responseType - Expected response type (default: "json")
|
|
217
|
-
* @returns Promise resolving to the response data
|
|
87
|
+
* Performs an HTTP DELETE request.
|
|
88
|
+
* @param req The request object containing URL and headers
|
|
89
|
+
* @param responseType Optional response parsing type
|
|
90
|
+
* @returns A promise that resolves to the parsed response
|
|
91
|
+
* @template T The expected response type
|
|
218
92
|
*/
|
|
219
93
|
delete<T = any>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
220
94
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @param
|
|
224
|
-
* @
|
|
225
|
-
* @
|
|
95
|
+
* Performs an HTTP PATCH request.
|
|
96
|
+
* @param req The request object containing URL, body, and headers
|
|
97
|
+
* @param responseType Optional response parsing type
|
|
98
|
+
* @returns A promise that resolves to the parsed response
|
|
99
|
+
* @template T The expected response type
|
|
226
100
|
*/
|
|
227
101
|
patch<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
228
102
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
103
|
+
* @ru Получает потоковый ответ (для SSE, больших файлов).
|
|
104
|
+
* @en Gets streaming response (for SSE, large files).
|
|
105
|
+
*/
|
|
106
|
+
stream(req: RequestInterface | string): Promise<StreamResponse>;
|
|
107
|
+
/**
|
|
108
|
+
* Performs an HTTP HEAD request.
|
|
109
|
+
* @param req The request object containing URL and headers
|
|
110
|
+
* @returns A promise that resolves when the request completes
|
|
234
111
|
*/
|
|
235
112
|
head(req: RequestInterface | string): Promise<{
|
|
236
113
|
status: number;
|
|
237
114
|
headers: Record<string, any>;
|
|
238
115
|
}>;
|
|
239
116
|
/**
|
|
240
|
-
* Clears the
|
|
241
|
-
* Removes all cached responses and resets the cache state.
|
|
117
|
+
* Clears the request cache.
|
|
242
118
|
*/
|
|
243
119
|
clearCache(): Promise<void>;
|
|
244
120
|
/**
|
|
@@ -266,8 +142,7 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
266
142
|
request<T = any>(url: string): RequestBuilder<T>;
|
|
267
143
|
/**
|
|
268
144
|
* Returns current statistics about the HTTP client's state.
|
|
269
|
-
*
|
|
270
|
-
* @returns Object containing various client statistics
|
|
145
|
+
* @returns An object containing cache size, request counts, and rate limit information
|
|
271
146
|
*/
|
|
272
147
|
getStats(): {
|
|
273
148
|
cacheSize: number;
|
|
@@ -275,104 +150,6 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
275
150
|
queuedRequests: number;
|
|
276
151
|
activeRequests: number;
|
|
277
152
|
currentRateLimit: number;
|
|
278
|
-
metricsSize: number;
|
|
279
153
|
};
|
|
280
154
|
}
|
|
281
|
-
/**
|
|
282
|
-
* Fluent request builder for making HTTP requests with a chainable API.
|
|
283
|
-
* Provides a convenient way to build and send HTTP requests with various options.
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* ```ts
|
|
287
|
-
* const client = new HttpClientImproved();
|
|
288
|
-
* const response = await client.request('https://api.example.com/data')
|
|
289
|
-
* .headers({ 'Authorization': 'Bearer token' })
|
|
290
|
-
* .query({ limit: 10, offset: 0 })
|
|
291
|
-
* .json()
|
|
292
|
-
* .send();
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
declare class RequestBuilder<T = any> {
|
|
296
|
-
private _url;
|
|
297
|
-
private _method;
|
|
298
|
-
private _headers;
|
|
299
|
-
private _body?;
|
|
300
|
-
private _responseType;
|
|
301
|
-
/**
|
|
302
|
-
* Creates a new request builder for the specified URL.
|
|
303
|
-
* @param url - The target URL for the request
|
|
304
|
-
*/
|
|
305
|
-
constructor(url: string);
|
|
306
|
-
/**
|
|
307
|
-
* Sets HTTP headers for the request.
|
|
308
|
-
* @param headers - Object containing header key-value pairs
|
|
309
|
-
* @returns The builder instance for chaining
|
|
310
|
-
*/
|
|
311
|
-
headers(headers: Record<string, string>): this;
|
|
312
|
-
/**
|
|
313
|
-
* Sets the request body data.
|
|
314
|
-
* @param bodyData - The body data to send with the request
|
|
315
|
-
* @returns The builder instance for chaining
|
|
316
|
-
*/
|
|
317
|
-
body(bodyData: any): this;
|
|
318
|
-
/**
|
|
319
|
-
* Sets the response type to JSON.
|
|
320
|
-
* @returns The builder instance for chaining
|
|
321
|
-
*/
|
|
322
|
-
json(): this;
|
|
323
|
-
/**
|
|
324
|
-
* Sets the response type to plain text.
|
|
325
|
-
* @returns The builder instance for chaining
|
|
326
|
-
*/
|
|
327
|
-
text(): this;
|
|
328
|
-
/**
|
|
329
|
-
* Sets the response type to XML.
|
|
330
|
-
* @returns The builder instance for chaining
|
|
331
|
-
*/
|
|
332
|
-
xml(): this;
|
|
333
|
-
/**
|
|
334
|
-
* Sets the HTTP method to POST.
|
|
335
|
-
* @returns The builder instance for chaining
|
|
336
|
-
*/
|
|
337
|
-
post(): this;
|
|
338
|
-
/**
|
|
339
|
-
* @ru Устанавливает потоковый режим ответа.
|
|
340
|
-
* @en Sets streaming response mode.
|
|
341
|
-
*/
|
|
342
|
-
stream(): this;
|
|
343
|
-
/**
|
|
344
|
-
* Sets the HTTP method to PUT.
|
|
345
|
-
* @returns The builder instance for chaining
|
|
346
|
-
*/
|
|
347
|
-
put(): this;
|
|
348
|
-
/**
|
|
349
|
-
* Sets the HTTP method to PATCH.
|
|
350
|
-
* @returns The builder instance for chaining
|
|
351
|
-
*/
|
|
352
|
-
patch(): this;
|
|
353
|
-
/**
|
|
354
|
-
* Sets the HTTP method to DELETE.
|
|
355
|
-
* @returns The builder instance for chaining
|
|
356
|
-
*/
|
|
357
|
-
delete(): this;
|
|
358
|
-
/**
|
|
359
|
-
* Adds query parameters to the URL.
|
|
360
|
-
* @param params - Object containing query parameter key-value pairs
|
|
361
|
-
* @returns The builder instance for chaining
|
|
362
|
-
*/
|
|
363
|
-
query(params: Record<string, string | number | boolean>): this;
|
|
364
|
-
/**
|
|
365
|
-
* Sets a JSON body for the request.
|
|
366
|
-
* Automatically sets the Content-Type header to application/json.
|
|
367
|
-
* @param body - The JSON body data
|
|
368
|
-
* @returns The builder instance for chaining
|
|
369
|
-
*/
|
|
370
|
-
jsonBody<T>(body: T): this;
|
|
371
|
-
/**
|
|
372
|
-
* Sends the HTTP request and returns the response.
|
|
373
|
-
* @returns Promise resolving to the response data
|
|
374
|
-
*/
|
|
375
|
-
send(): Promise<T>;
|
|
376
|
-
}
|
|
377
|
-
export {};
|
|
378
155
|
//# sourceMappingURL=HttpClientImproved.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClientImproved.d.ts","sourceRoot":"","sources":["../../../../src/Hyperttp/Core/HttpClientImproved.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpClientImproved.d.ts","sourceRoot":"","sources":["../../../../src/Hyperttp/Core/HttpClientImproved.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzC,OAAO,EAEL,mBAAmB,EACnB,iBAAiB,EAGjB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,YAAY,EAEZ,cAAc,EAEf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMlD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,mBAAmB;IACpE,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAc;IAE9B,OAAO,CAAC,QAAQ,CAAmC;IAEnD,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,OAAO,CAAoB;IAEnC,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,oBAAoB,CAA6B;IAEzD,OAAO,CAAC,cAAc,CAAqC;IAE3D;;;OAGG;gBACS,OAAO,CAAC,EAAE,iBAAiB;IAgFvC;;;OAGG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAIxD;;;OAGG;IACH,YAAY,IAAI,SAAS;IAIzB;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI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