Skip to content

Commit e40f3db

Browse files
committed
docs: enhance README with advanced features including retry configuration, response data handling, and ETag support
1 parent 11c1cdf commit e40f3db

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

nodejs/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,52 @@ client.getMe().then(me => {
3232
})
3333
```
3434

35+
## Advanced Features
36+
37+
### Retry Configuration
38+
39+
The client supports automatic retry for failed requests with exponential backoff. You can configure retry behavior when creating the client:
40+
41+
```javascript
42+
const client = new HackMDAPI('YOUR_ACCESS_TOKEN', 'https://api.hackmd.io/v1', {
43+
retryConfig: {
44+
maxRetries: 3, // Maximum number of retry attempts
45+
baseDelay: 100 // Base delay in milliseconds for exponential backoff
46+
}
47+
})
48+
```
49+
50+
The client will automatically retry requests that fail with:
51+
- 5xx server errors
52+
- 429 Too Many Requests errors
53+
- Network errors
54+
55+
### Response Data Handling
56+
57+
By default, the client automatically unwraps the response data from the Axios response object. You can control this behavior using the `unwrapData` option:
58+
59+
```javascript
60+
// Get raw Axios response (includes headers, status, etc.)
61+
const response = await client.getMe({ unwrapData: false })
62+
63+
// Get only the data (default behavior)
64+
const data = await client.getMe({ unwrapData: true })
65+
```
66+
67+
### ETag Support
68+
69+
The client supports ETag-based caching for note retrieval. You can pass an ETag to check if the content has changed:
70+
71+
```javascript
72+
// First request
73+
const note = await client.getNote('note-id')
74+
const etag = note.etag
75+
76+
// Subsequent request with ETag
77+
const updatedNote = await client.getNote('note-id', { etag })
78+
// If the note hasn't changed, the response will have status 304
79+
```
80+
3581
## API
3682

3783
See the [code](./src/index.ts) and [typings](./src/type.ts). The API client is written in TypeScript, so you can get auto-completion and type checking in any TypeScript Language Server powered editor or IDE.

0 commit comments

Comments
 (0)