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

<Meta title='@dxtmisha/en/functional/Composables/useApiPut - PUT Request Execution'/>

# `useApiPut`

Returns an object with a loading state and a `send` method for executing API `PUT` requests.

**Parameters:**
- `path?: RefOrNormal<string | undefined>` — Path to the API endpoint (can be reactive).
- `action?: (data: Return | undefined) => Promise<void> | void` — Callback action to perform after the request completes successfully.
- `transformation?: (data: T) => Return` — Function to transform the response data before it is returned or passed to the `action`.
- `toData: boolean = true` — Whether to extract the `data` field from the response.
- `options?: ApiOptions` — Additional request options (`ApiFetch` object parameter).
- `apiInstance?: ApiInstance` — API instance to use for the request. Defaults to `Api.getItem()`.

**Returns:**
An object with the following properties:
- `loading: Ref<boolean>` — Reactive loading state. It becomes `true` while the request is in progress and `false` after it completes or fails.
- `send(request?: Request): Promise<Return | undefined>` — An asynchronous method for sending the `PUT` request. It automatically manages the `loading` state, applies the transformation function to the response, executes the `action` callback on success, and safely handles errors by logging them to the console.

```typescript
import { useApiPut } from '@dxtmisha/functional'

const { loading, send } = useApiPut(
  '/api/update',
  (data) => console.log('Action complete:', data),
  (raw) => ({ ...raw, processed: true }),
  true,
  { cache: false }
)

const handleUpdate = async () => {
  const result = await send({ id: 1, name: 'New Name' })
  console.log('Final Result:', result)
}
```
