1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| // RESTful API の一般的なメソッド
// GET: リソースの取得
fetch('/api/users', { method: 'GET' });
// POST: リソースの作成
fetch('/api/users', {
method: 'POST',
body: JSON.stringify({ name: 'John' })
});
// PUT: リソースの更新(全体)
fetch('/api/users/1', {
method: 'PUT',
body: JSON.stringify({ name: 'John', email: 'john@example.com' })
});
// PATCH: リソースの部分更新
fetch('/api/users/1', {
method: 'PATCH',
body: JSON.stringify({ name: 'John Updated' })
});
// DELETE: リソースの削除
fetch('/api/users/1', { method: 'DELETE' });
|