Skip to content

Commit e03549f

Browse files
committed
レスポンスの取得に関する表現を簡略化
1 parent dc23271 commit e03549f

File tree

3 files changed

+1
-5
lines changed

3 files changed

+1
-5
lines changed

docs/3-web-servers/06-fetch-api/_samples/fetch-weather-json/public/script.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
async function fetchWeather() {
22
const response = await fetch("/weather");
3-
// レスポンスをJSONとして取得
43
const weather = await response.json();
54
document.getElementById("condition").textContent = weather.condition;
65
document.getElementById("temperature").textContent = weather.temperature;

docs/3-web-servers/06-fetch-api/_samples/fetch-weather/public/script.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ async function fetchWeather() {
33
// http://localhost:3000/weather にHTTPリクエストを送信
44
// fetch関数は非同期処理を行うため、await演算子を適用して完了を待機する
55
const response = await fetch("/weather");
6-
// レスポンスをテキストとして取得
76
const weather = await response.text();
87
document.getElementById("weather").textContent = weather;
98
}

docs/3-web-servers/06-fetch-api/index.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ async function fetchWeather() {
4545
// http://localhost:3000/weather にHTTPリクエストを送信
4646
// fetch関数は非同期処理を行うため、await演算子を適用して完了を待機する
4747
const response = await fetch("/weather");
48-
// レスポンスをテキストとして取得
4948
const weather = await response.text();
5049
document.getElementById("weather").textContent = weather;
5150
}
@@ -115,7 +114,7 @@ fetchOpenStatus();
115114
次の例では、Fetch APIを用いて、サーバーから現在の天気と気温を取得しています。前項のサンプルアプリケーションとは、次の点が異なっています。
116115

117116
- サーバー側は、Expressが提供する[`Response#json`メソッド](https://expressjs.com/ja/api.html#res.json)を用いてレスポンスを送信しています。このメソッドは、引数として渡されたオブジェクトを<Term>JSON</Term>に変換してレスポンスとして返します。
118-
- クライアント側は、ブラウザが提供する[`Response#json`メソッド](https://developer.mozilla.org/ja/docs/Web/API/Response/json)を用いてレスポンスを取得しています。このメソッドは、レスポンスの内容を<Term>JSON</Term>として解析し、JavaScriptのオブジェクトとして返します
117+
- クライアント側は、ブラウザが提供する[`Response#json`メソッド](https://developer.mozilla.org/ja/docs/Web/API/Response/json)を用いて、<Term>JSON</Term>形式のレスポンスをJavaScriptオブジェクトとして取得します
119118

120119
```javascript title="main.mjs (サーバーとして動作するJavaScript)"
121120
import express from "express";
@@ -142,7 +141,6 @@ app.listen(3000);
142141
```javascript title="public/script.js (ブラウザ上で動作するJavaScript)"
143142
async function fetchWeather() {
144143
const response = await fetch("/weather");
145-
// レスポンスをJSONとして取得
146144
const weather = await response.json();
147145
document.getElementById("condition").textContent = weather.condition;
148146
document.getElementById("temperature").textContent = weather.temperature;

0 commit comments

Comments
 (0)