Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ktranish authored Nov 17, 2024
1 parent 3fa2ed9 commit abe0491
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
- 📈 **Lifecycle Logging**: Hook into request, response, and error events.
- 📊 **Built-in Analytics**: Monitor total requests, response times, success rates, and errors.

## Installation
## Getting Started

### Installation

Install Hook via your preferred package manager:

Expand All @@ -29,9 +31,9 @@ yarn add @ktranish/hook
pnpm add @ktranish/hook
```

## Usage
### Usage

### 1. Basic GET Request
#### 1. Basic GET Request

```tsx
import hook from '@ktranish/hook';
Expand All @@ -42,7 +44,7 @@ const fetchData = async () => {
};
```

### 2. POST Request with Data
#### 2. POST Request with Data

```tsx
const createResource = async () => {
Expand All @@ -51,7 +53,7 @@ const createResource = async () => {
};
```

### 3. Global Configuration
#### 3. Global Configuration

Configure global headers, credentials, or other fetch options:

Expand All @@ -66,7 +68,7 @@ configureGlobal({
await hook.get('https://api.example.com/resource');
```

### 4. Local Overrides
#### 4. Local Overrides

Override global configurations for specific requests:

Expand All @@ -77,9 +79,9 @@ await hook.get('https://api.example.com/resource', {
});
```

### 5. Lifecycle Logging
#### 5. Lifecycle Logging

#### Global Logging
**Global Logging**

Configure global loggers to track all HTTP requests:

Expand All @@ -95,7 +97,7 @@ configureLogger({
await hook.get('https://api.example.com/resource'); // Automatically logged
```

#### Local Logging
**Local Logging**

Override global logging with a local logger:

Expand All @@ -113,11 +115,11 @@ await hook.post(
);
```

### 6. Analytics
#### 6. Analytics

Hook comes with built-in analytics to monitor your HTTP activity.

#### Retrieve Analytics
**Retrieve Analytics**

```tsx
import { getAnalytics } from '@ktranish/hook';
Expand All @@ -126,7 +128,7 @@ const analytics = getAnalytics();
console.log('Analytics:', analytics);
```

#### Reset Analytics
**Reset Analytics**

```tsx
import { resetAnalytics } from '@ktranish/hook';
Expand All @@ -135,7 +137,7 @@ resetAnalytics();
console.log('Analytics reset.');
```

#### Sample Analytics Data
**Sample Analytics Data**

```json
{
Expand All @@ -156,7 +158,7 @@ console.log('Analytics reset.');
}
```

### 7. Custom Fetch Options
#### 7. Custom Fetch Options

Hook supports all valid Fetch API options:

Expand Down

0 comments on commit abe0491

Please sign in to comment.