@rtorcato/api-http 0.2.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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Richard Torcato
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @rtorcato/api-http
|
|
2
|
+
|
|
3
|
+
Typed HTTP client over native `fetch` — base URL, default headers, timeout, optional retry, and errors normalized to [`@rtorcato/api-errors`](https://github.com/rtorcato/api-common/tree/main/packages/api-errors).
|
|
4
|
+
|
|
5
|
+
No `axios`, no wrapper dependency — built on Node's global `fetch` and `AbortSignal.timeout` (Node 22+).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @rtorcato/api-http @rtorcato/api-errors
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createHttpClient } from '@rtorcato/api-http'
|
|
17
|
+
|
|
18
|
+
const api = createHttpClient({
|
|
19
|
+
baseURL: 'https://api.example.com',
|
|
20
|
+
headers: { authorization: `Bearer ${token}` },
|
|
21
|
+
timeoutMs: 10_000,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const user = await api.get<{ id: string; name: string }>('/users/me')
|
|
25
|
+
await api.post('/users', { name: 'Ada' })
|
|
26
|
+
await api.get('/items', { query: { page: 2, q: 'hi' } })
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `get` / `delete` — `(path, options?)`
|
|
30
|
+
- `post` / `put` / `patch` — `(path, body?, options?)` — `body` is JSON-encoded with a `content-type: application/json` header.
|
|
31
|
+
|
|
32
|
+
## Errors
|
|
33
|
+
|
|
34
|
+
Non-2xx responses throw an `HttpError` (from `@rtorcato/api-errors`) carrying the status and a message pulled from the response body (`{ message }` / `{ error }` / raw text), so it slots straight into the `api-errors-express` / `api-errors-hono` error handlers. Network failures throw `HttpError` with status `0` and code `network_error`.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { HttpError } from '@rtorcato/api-errors'
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
await api.get('/missing')
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (err instanceof HttpError && err.status === 404) { /* … */ }
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Options
|
|
47
|
+
|
|
48
|
+
| Option | Default | |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `baseURL` | — | prepended to every request path |
|
|
51
|
+
| `headers` | — | sent on every request (per-request headers merge on top) |
|
|
52
|
+
| `timeoutMs` | `30_000` | per-request timeout (override per call) |
|
|
53
|
+
| `retries` | `0` | retry attempts on network error or 5xx |
|
|
54
|
+
| `retryDelayMs` | `200` | fixed delay between retries |
|
|
55
|
+
|
|
56
|
+
Per-request options: `{ headers, query, timeoutMs, signal }`. A caller `signal` is combined with the timeout signal.
|
|
57
|
+
|
|
58
|
+
Source: https://github.com/rtorcato/api-common/tree/main/packages/api-http
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface HttpClientOptions {
|
|
2
|
+
/** Prepended to every request path. */
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
/** Sent on every request (per-request headers merge on top). */
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
/** Per-request timeout in ms. Default: 30_000. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
/** Retry attempts on network error or 5xx. Default: 0 (no retry). */
|
|
9
|
+
retries?: number;
|
|
10
|
+
/** Fixed delay between retries in ms. Default: 200. */
|
|
11
|
+
retryDelayMs?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RequestOptions {
|
|
14
|
+
/** Merged on top of the client's default headers. */
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/** Appended as a query string; `undefined` values are skipped. */
|
|
17
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
18
|
+
/** Overrides the client timeout for this request. */
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
/** Caller abort signal — combined with the timeout signal. */
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export interface HttpClient {
|
|
24
|
+
get<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
|
|
25
|
+
delete<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
|
|
26
|
+
post<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
27
|
+
put<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
28
|
+
patch<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a typed HTTP client bound to a base URL and default headers.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const api = createHttpClient({ baseURL: 'https://api.example.com', headers: { authorization: `Bearer ${token}` } })
|
|
36
|
+
* const user = await api.get<{ id: string }>('/users/me')
|
|
37
|
+
* await api.post('/users', { name: 'Ada' })
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Non-2xx responses throw an `HttpError` (from `@rtorcato/api-errors`) carrying the
|
|
41
|
+
* status and a message pulled from the response body, so it slots straight into the
|
|
42
|
+
* error-handler middleware. Network failures throw `HttpError` with status `0` and
|
|
43
|
+
* code `network_error`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createHttpClient(clientOptions?: HttpClientOptions): HttpClient;
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,iBAAiB;IACjC,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,cAAc;IAC9B,qDAAqD;IACrD,OA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ep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
3
|
+
function buildUrl(baseURL, path, query) {
|
|
4
|
+
const url = baseURL
|
|
5
|
+
? new URL(path, baseURL.endsWith('/') ? baseURL : `${baseURL}/`)
|
|
6
|
+
: new URL(path);
|
|
7
|
+
if (query) {
|
|
8
|
+
for (const [key, value] of Object.entries(query)) {
|
|
9
|
+
if (value !== undefined)
|
|
10
|
+
url.searchParams.set(key, String(value));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return url.toString();
|
|
14
|
+
}
|
|
15
|
+
/** Pull a human-readable message out of an error response body (JSON `{message|error}` or raw text). */
|
|
16
|
+
function messageFromBody(text, statusText) {
|
|
17
|
+
if (!text)
|
|
18
|
+
return statusText || 'Request failed';
|
|
19
|
+
try {
|
|
20
|
+
const json = JSON.parse(text);
|
|
21
|
+
if (json && typeof json === 'object') {
|
|
22
|
+
const m = json['message'] ?? json['error'];
|
|
23
|
+
if (typeof m === 'string')
|
|
24
|
+
return m;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// not JSON — fall through to the raw text
|
|
29
|
+
}
|
|
30
|
+
return text;
|
|
31
|
+
}
|
|
32
|
+
async function parseBody(res) {
|
|
33
|
+
if (res.status === 204 || res.headers.get('content-length') === '0')
|
|
34
|
+
return undefined;
|
|
35
|
+
const text = await res.text();
|
|
36
|
+
if (!text)
|
|
37
|
+
return undefined;
|
|
38
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
39
|
+
if (contentType.includes('application/json'))
|
|
40
|
+
return JSON.parse(text);
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
async function request(client, method, path, body, options = {}) {
|
|
44
|
+
const url = buildUrl(client.baseURL, path, options.query);
|
|
45
|
+
const headers = { ...client.headers, ...options.headers };
|
|
46
|
+
let payload;
|
|
47
|
+
if (body !== undefined) {
|
|
48
|
+
payload = JSON.stringify(body);
|
|
49
|
+
headers['content-type'] ??= 'application/json';
|
|
50
|
+
}
|
|
51
|
+
const timeoutMs = options.timeoutMs ?? client.timeoutMs ?? 30_000;
|
|
52
|
+
const retries = client.retries ?? 0;
|
|
53
|
+
const retryDelayMs = client.retryDelayMs ?? 200;
|
|
54
|
+
for (let attempt = 0;; attempt++) {
|
|
55
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
56
|
+
const signal = options.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal;
|
|
57
|
+
let res;
|
|
58
|
+
try {
|
|
59
|
+
res = await fetch(url, { method, headers, body: payload, signal });
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
// Network failure or timeout. Retry if attempts remain, else normalize.
|
|
63
|
+
if (attempt < retries) {
|
|
64
|
+
await sleep(retryDelayMs);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const message = err instanceof Error ? err.message : 'Network request failed';
|
|
68
|
+
throw new HttpError(0, message, 'network_error');
|
|
69
|
+
}
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
if (res.status >= 500 && attempt < retries) {
|
|
72
|
+
await sleep(retryDelayMs);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const text = await res.text();
|
|
76
|
+
throw new HttpError(res.status, messageFromBody(text, res.statusText), 'http_error');
|
|
77
|
+
}
|
|
78
|
+
return parseBody(res);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a typed HTTP client bound to a base URL and default headers.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const api = createHttpClient({ baseURL: 'https://api.example.com', headers: { authorization: `Bearer ${token}` } })
|
|
87
|
+
* const user = await api.get<{ id: string }>('/users/me')
|
|
88
|
+
* await api.post('/users', { name: 'Ada' })
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* Non-2xx responses throw an `HttpError` (from `@rtorcato/api-errors`) carrying the
|
|
92
|
+
* status and a message pulled from the response body, so it slots straight into the
|
|
93
|
+
* error-handler middleware. Network failures throw `HttpError` with status `0` and
|
|
94
|
+
* code `network_error`.
|
|
95
|
+
*/
|
|
96
|
+
export function createHttpClient(clientOptions = {}) {
|
|
97
|
+
return {
|
|
98
|
+
get: (path, options) => request(clientOptions, 'GET', path, undefined, options),
|
|
99
|
+
delete: (path, options) => request(clientOptions, 'DELETE', path, undefined, options),
|
|
100
|
+
post: (path, body, options) => request(clientOptions, 'POST', path, body, options),
|
|
101
|
+
put: (path, body, options) => request(clientOptions, 'PUT', path, body, options),
|
|
102
|
+
patch: (path, body, options) => request(clientOptions, 'PATCH', path, body, options),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAsChD,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAEnE,SAAS,QAAQ,CAChB,OAA2B,EAC3B,IAAY,EACZ,KAA+B;IAE/B,MAAM,GAAG,GAAG,OAAO;QAClB,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC;QAChE,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;IAChB,IAAI,KAAK,EAAE,CAAC;QACX,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS;gBAA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AE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC;QAChF,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC;KACpF,CAAA;AACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rtorcato/api-http",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Typed HTTP client over native fetch — base URL, default headers, timeout, and errors normalized to @rtorcato/api-errors.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Richard Torcato",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@rtorcato/api-errors": "0.2.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "~6.0.3"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"api",
|
|
33
|
+
"nodejs",
|
|
34
|
+
"typescript",
|
|
35
|
+
"http",
|
|
36
|
+
"fetch",
|
|
37
|
+
"client"
|
|
38
|
+
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/rtorcato/api-common.git",
|
|
42
|
+
"directory": "packages/api-http"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/rtorcato/api-common/tree/main/packages/api-http#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/rtorcato/api-common/issues"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.build.json",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
}
|
|
53
|
+
}
|