11# Getting Started
22
3- ` @dfsync/client ` is a lightweight TypeScript HTTP client designed for reliable service-to-service communication.
3+ ` @dfsync/client ` is a lightweight HTTP client built around a predictable request lifecycle for service-to-service communication in Node.js .
44
55It provides sensible defaults for:
66
@@ -11,19 +11,20 @@ It provides sensible defaults for:
1111
1212The client focuses on predictable behavior, extensibility, and a clean developer experience.
1313
14- ## What you get
14+ ## Main features
15+
16+ - predictable request lifecycle
17+ - request ID propagation (` x-request-id ` )
18+ - request cancellation via ` AbortSignal `
19+ - built-in retry with configurable policies
20+ - lifecycle hooks: ` beforeRequest ` , ` afterResponse ` , ` onError `
1521
1622- typed responses
17- - simple client creation
18- - request timeout support
1923- automatic JSON parsing
20- - text response support
21- - consistent error handling with structured error classes
22- - auth support: ` bearer ` , ` API key ` and custom
23- - lifecycle hooks: ` beforeRequest ` , ` afterResponse ` , ` onError `
24+ - consistent error handling
25+
26+ - auth support: bearer, API key, custom
2427- support for ` GET ` , ` POST ` , ` PUT ` , ` PATCH ` , and ` DELETE `
25- - retry policies
26- - custom ` fetch ` support
2728
2829## Quick example
2930
@@ -41,53 +42,22 @@ const client = createClient({
4142});
4243
4344const user = await client .get <User >(' /users/1' );
44-
45- console .log (user .id );
46- console .log (user .name );
4745```
4846
4947## How requests work
5048
51- A request in ` @dfsync/client ` goes through the following lifecycle:
52-
53- 1 . Build request URL
54-
55- The final URL is constructed from ` baseUrl ` , ` path ` , and optional query parameters.
56-
57- 2 . Merge headers
58-
59- Default headers, client-level headers, and request-level headers are combined.
60-
61- 3 . Apply authentication
62-
63- The configured auth strategy (Bearer, API key, or custom) is applied to the request.
64-
65- 4 . Run ` beforeRequest ` hooks
66-
67- Hooks can modify the request before it is sent.
68-
69- 5 . Execute the HTTP request
70-
71- The request is sent using the Fetch API.
72-
73- 6 . Retry if necessary
74-
75- If the request fails with a retryable error, it may be retried according to the configured retry policy.
76-
77- 7 . Parse the response
78-
79- The response body is parsed automatically:
80- - JSON → parsed object
81- - text → string
82- - ` 204 No Content ` → ` undefined `
83-
84- 8 . Handle errors
85-
86- Non-success responses and network failures are converted into structured errors.
87-
88- 9 . Run response hooks
89- - ` afterResponse ` runs for successful responses
90- - ` onError ` runs when an error occurs
49+ A request in ` @dfsync/client ` follows a predictable lifecycle:
50+
51+ 1 . create request context
52+ 2 . build final URL from ` baseUrl ` , ` path ` , and query params
53+ 3 . merge client and request headers
54+ 4 . apply authentication
55+ 5 . attach request metadata (e.g. ` x-request-id ` )
56+ 6 . run ` beforeRequest ` hooks
57+ 7 . send request with ` fetch `
58+ 8 . retry on failure (if configured)
59+ 9 . parse response (JSON, text, or ` undefined ` )
60+ 10 . run ` afterResponse ` or ` onError ` hooks
9161
9262## Runtime requirements
9363
0 commit comments