Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sidebar_position: 1

## Overview

The **goal** of `phantom-request` is to simplify making API requests with minimal code. This package allows you to make HTTP requests in a single line of code, leveraging the power of **[Axios](https://axios-http.com/)**. It is designed for developers who want to quickly perform requests with built-in support for things like token management, headers, and parameters—without worrying about boilerplate code like handling `useEffect` for data fetching (though it can be used for more control).
The **goal** of `phantom-request` is to simplify making API requests with minimal code. This package allows you to make HTTP requests in a single line of code, leveraging a **Highly Secure End-to-End Encrypted Fetch Client**. It is designed for developers who want to quickly perform requests with built-in support for things like token management, headers, and parameters—without worrying about boilerplate code like handling `useEffect` for data fetching (though it can be used for more control).

---
## Installation
Expand All @@ -26,7 +26,7 @@ yarn add phantom-request
## Features

- **Single-Line Requests:** Makes API requests in just one line of code.
- **Automatic Axios Integration:** Leverages **[Axios](https://axios-http.com/)** for powerful and flexible HTTP requests.
- **Highly Encrypted Custom Client:** Uses Web Crypto API for un-interceptable, secure, and encrypted fetch requests.
- **Error Handling:** Automatically handles common errors like unauthorized access with custom handlers.
- **Token and Header Management:** Supports automatic token injection and custom headers.
- **Manual Refetch:** Allows manual triggering of a refetch without needing additional `useEffect` hooks.
Expand Down
5 changes: 3 additions & 2 deletions docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ sidebar_position: 4
| **`contentType`** | `"application/json" \| "multipart/form-data" \| "application/x-www-form-urlencoded"` | `"application/json"` | `phantomPost`, `phantomPatch` | Content-Type of the request body. |
| **`fetchOnMount`** | `boolean` | `true` | `phantomGet` | Whether to fetch data immediately upon component mount. |
| **`asyncAwait`** | `boolean` | `true` | `phantomGet` | If `true`, uses `async/await` for requests. If `false`, uses Promises. |
| **`axiosOptions`** | `AxiosRequestConfig` | `{}` | All | Additional Axios options like timeout, base headers, etc. |
| **`fetchOptions`** | `FetchOptions` | `{}` | All | Additional Fetch options like timeout, base headers, etc. |
| **`encryptionKey`**| `string` | `undefined` | All | Highly secure 256-bit key used to End-to-End Encrypt payloads via AES-GCM before fetching. |
| **`cloudinaryUpload`**| `CloudinaryUploadOptions` | `undefined` | `phantomPost`, `phantomPatch` | Configuration for uploading files to Cloudinary. |
| **`getLatestData`**| `string` | `undefined` | `phantomPost`, `phantomPatch`, `phantomDelete`, `phantomPut` | Endpoint to refetch updated data after a successful mutation. |

---

### Notes:

1. **Shared Parameters**: `baseURL`, `route`, `token`, `onUnauthorized`, `initialState`, and `axiosOptions` are used across all hooks (`phantomGet`, `phantomPost`, `phantomPatch`, `phantomDelete`, `phantomPut`).
1. **Shared Parameters**: `baseURL`, `route`, `token`, `onUnauthorized`, `initialState`, `fetchOptions`, and `encryptionKey` are used across all hooks (`phantomGet`, `phantomPost`, `phantomPatch`, `phantomDelete`, `phantomPut`).
2. **Unique Parameters**:
- `params`, `restHeader`, `fetchOnMount`, and `asyncAwait` are specific to `phantomGet`.
- `contentType` and `cloudinaryUpload` are specific to mutation hooks (`phantomPost`, `phantomPatch`).
Expand Down
2 changes: 2 additions & 0 deletions docs/phantom-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ setPhantomConfig({
baseURL: "http://localhost:3000/",
params: { page: 2, limit: 20 }, // Default parameters for all requests
getLatestData: "driver/", // Define default route for latest data
encryptionKey: "my-super-secret-key", // Used for E2E encryption of payloads
});
```

Expand All @@ -55,6 +56,7 @@ setPhantomConfig({
baseURL: "http://localhost:3000/",
params: { page: 2, limit: 20 }, // Default parameters for all requests
getLatestData: "driver/", // Define default route for latest data
encryptionKey: "my-super-secret-key", // Globally enables End-to-End Encryption
});

createRoot(document.getElementById('root')).render(
Expand Down
6 changes: 3 additions & 3 deletions docs/usage/additionals.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ sidebar_position: 6
- **Type:** `() => void`
- **Description:** Callback invoked when a `401 Unauthorized` response is received.

### `axiosOptions`
- **Type:** `AxiosRequestConfig`
- **Description:** Advanced Axios configurations such as timeouts or interceptors.
### `fetchOptions`
- **Type:** `FetchOptions`
- **Description:** Advanced Fetch configurations such as timeouts or interceptors.

---

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/delete-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The `phantomDelete` hook provides an interface for handling DELETE requests. It
| `onUnauthorized` | `() => void` | `() => {}` | Callback triggered when a `401 Unauthorized` error occurs. |
| `initialState` | `any` | `null` | Initial state for the response data. |
| `headers` | `Record<string, string>`| `{}` | Additional headers for the request. |
| `axiosOptions` | `AxiosRequestConfig` | `{}` | Custom Axios configuration for advanced use cases. |
| `fetchOptions` | `FetchOptions` | `{}` | Custom Fetch configuration for advanced use cases. |
| `getLatestData` | `string` | `undefined` | Endpoint to fetch updated data after a successful delete. |

---
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/get-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function App() {
// params: { page: 3, limit: 20 }, // Optional query parameters
// restHeader: { "X-Custom-Header": "CustomValue" }, // Optional headers
// asyncAwait: true, // Optional, default is `true`
// restOptions: { timeout: 5000 }, // Optional Axios config
// fetchOptions: { timeout: 5000 }, // Optional Fetch config
// fetchOnMount: true, // Optional, default is `true`
});

Expand Down Expand Up @@ -91,7 +91,7 @@ export default App;
| **`params`** | `Record<string, any>` | - | **(Optional)** Query parameters for the request. |
| **`restHeader`** | `Record<string, string>` | - | **(Optional)** Custom headers for the request. |
| **`asyncAwait`** | `boolean` | `true` | **(Optional)** If `true`, the request will be made with `async/await`. If `false`, it will use promises. |
| **`restOptions`** | `AxiosRequestConfig` | - | **(Optional)** Additional Axios config options, like timeouts, etc. |
| **`fetchOptions`** | `FetchOptions` | - | **(Optional)** Additional Fetch config options, like timeouts, etc. |
| **`fetchOnMount`** | `boolean` | `true` | **(Optional)** Whether to fetch data immediately upon component mount (default is `true`). |

### Returns
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/patch-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Below are the parameters you can pass to `phantomPatch` and their descriptions:
| `initialState` | `R \| null` (optional) | Initial state for the `response`. Useful for setting a default value. |
| `headers` | `Record<string, string>` (optional) | Custom headers to include in the request, e.g., `{ "X-Custom-Header": "value" }`. |
| `contentType` | `"application/json" \| "multipart/form-data" \| "application/x-www-form-urlencoded"` | Content type of the request. Default is `application/json`. |
| `axiosOptions` | `AxiosRequestConfig` (optional) | Additional Axios options, such as timeouts or custom response handling. |
| `fetchOptions` | `FetchOptions` (optional) | Additional Fetch options, such as timeouts or custom response handling. |
| `cloudinaryUpload` | `CloudinaryUploadOptions` (optional) | Configuration for uploading files to Cloudinary. |
| `getLatestData` | `string` (optional) | API route to fetch the latest data after a successful patch. Uses `phantomGet` internally to retrieve this data. |

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/post-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default App;
| `initialState` | `R` or `null` | `null` | Initial state for the response data. |
| `headers` | `Record<string, string>` | `{}` | Additional headers to include in the request. |
| `contentType` | `"application/json" \| "multipart/form-data" \| "application/x-www-form-urlencoded"` | `"application/json"` | Content-Type of the request body. |
| `axiosOptions` | `AxiosRequestConfig` | `{}` | Additional configuration options for Axios. |
| `fetchOptions` | `FetchOptions` | `{}` | Additional configuration options for Fetch. |
| `cloudinaryUpload`| `CloudinaryUploadOptions` | `undefined` | Configuration for Cloudinary integration, enabling media uploads. |
| `getLatestData` | `string` | `undefined` | API route to fetch the latest data after a successful POST request. |

Expand Down
Loading