Configuration Options
A comprehensive overview of all available configuration options.
Here's a breakdown of the configuration options available in hmm-api
:
1. baseUrl
- Default: None
- Purpose: Sets a common base URL for all API requests.
- Example:
const apiClient = new ApiClient({ baseUrl: "https://api.example.com" });
2. toast
- Default: None
- Purpose: Integrates a toast library for notifications.
- Example:
import MyToastLibrary from "my-toast-library"; const apiClient = new ApiClient({ toast: MyToastLibrary });
3. globalHeaders
- Default: None
- Purpose: Sets headers included in all requests.
- Example:
const apiClient = new ApiClient({ globalHeaders: { Authorization: "Bearer your_token", "Content-Type": "application/json", }, });
4. showGlobalErrorToast
- Default:
true
- Purpose: Controls global toast display.
- Example:
const apiClient = new ApiClient({ showGlobalErrorToast: true });
5. showGlobalSuccessToast
- Default:
false
- Purpose: Controls global toast display.
- Example:
const apiClient = new ApiClient({ showGlobalSuccessToast: true });
6. parseErrorResponse
- Default: Default parser
- Purpose: Customizes error message parsing.
- Example:
const apiClient = new ApiClient({ parseErrorResponse: (error) => { // default error parsing logic if (typeof error === "string") return { message: error }; if (error.message) return { message: error.message }; if (error.error?.message) return { message: error.error.message }; return { message: "An unexpected error occurred" }; }, });
7. parseErrorResponse
- Default: Default parser
- Purpose: Customizes error message parsing.
- Example:
const apiClient = new ApiClient({ parseErrorResponse: (response) => { // default error parsing logic if (typeof response === "string") return { message: response }; if (response.message) return { message: response.message }; return { message: "Request succeeded" }; }, });
8. credentials
- Default:
same-origin
- Purpose: Controls credential handling.
- Example:
const apiClient = new ApiClient({ credentials: "include" });
By customizing these options, you can tailor hmm-api
to your specific project needs, ensuring a robust and flexible HTTP client solution.