---
title: "useAppFetch"
description: "useAppFetch() は surface の authenticated data-plane fetcher を返します。App-relative path と通常の RequestInit を渡すと、Core が選択 environment の backend 配下へ resolve し、bearer credential と mount c…"
url: "https://sotaagents.ai/ja/manual/developer-guide/use-app-fetch"
generated_by: "sotaagents-ldp"
docs_index: "https://sotaagents.ai/manual/llms.txt"
locale: "ja"
---

# useAppFetch

`useAppFetch()` は surface の authenticated data-plane fetcher を返します。App-relative path と通常の `RequestInit` を渡すと、Core が選択 environment の backend 配下へ resolve し、bearer credential と mount cancellation を付与し、期限切れ credential を一度だけ refresh します。

TSX

```
import { useState } from 'react';
import { useAppFetch } from '@sota/platform';

export function SaveSettingsButton() {
  const appFetch = useAppFetch();
  const [status, setStatus] = useState('idle');
  async function save() {
    setStatus('saving');
    const response = await appFetch('/settings', {
      method: 'PUT',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify({ digest: 'weekly' }),
    });
    if (!response.ok) {
      setStatus('error');
      return;
    }
    const saved = await response.json();
    setStatus(saved.digest === 'weekly' ? 'saved' : 'error');
  }
  return <button type="button" onClick={save}>{status}</button>;
}
```

返り値は標準 `Response` です。JSON parse と domain error は app logic です。Cross-origin URL と scoped base path の外へ出る path は拒否されます。Authorization header を自分で付与・保存しません。

| Case | Behavior |
| --- | --- |
| 通常 response | Non-2xx を含めそのまま返します。 |
| Credential expired | 同じ environment の descriptor を refresh して一度だけ retry します。 |
| Surface unmount | Request signal を abort します。 |
| One-shot stream body | Credential retry に備えて事前に tee します。 |
