import {Meta} from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Classes/ApiDefault - Default API Request Data'/>

# ApiDefault Class

A class for managing default data for API requests. It allows setting base parameters that should be included in every request, supporting both standard objects and `FormData`. This is useful for centrally defining common fields such as tokens, application IDs, or localization settings.

> `ApiDefault` is an **auxiliary class**, designed for managing request defaults. In most cases, it is recommended to define these through the `requestDefault` parameter in the global `Api` configuration.

## Key Features

- **Centralized Defaults** — Define common parameters once for all API calls.
- **Support for Multiple Formats** — Works seamlessly with both plain JavaScript objects and `FormData`.
- **Intelligent Merging** — Merges defaults with request-specific data, prioritizing the actual request data if keys overlap.
- **Chainable API** — Supports a fluent interface for setting parameters.

## Methods

### Action

#### `request`

Merges the stored default data into a provided request object or `FormData` instance. If the input is a plain object, it returns a new merged object. If the input is `FormData`, it adds missing keys directly to the instance.

**Parameters:**
- `request: ApiFetch['request']` — The original request data (Object, FormData, or String).

**Returns:** `ApiFetch['request']` — The transformed request data.

### Check

- `is(): boolean` — Checks if any default data has been set.
- `get(): ApiDefaultValue | undefined` — Returns the current default data object.

### Configuration

- `set(request: ApiDefaultValue): this` — Sets the default data for all future requests.

## Types

#### `ApiDefaultValue`
A plain object representing default parameters.
- `[key: string]: any` — Key-value pairs to be used as defaults.
