Response()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

Response() コンストラクターは、新しい Response オブジェクトを生成します。

構文

js
new Response()
new Response(body)
new Response(body, options)

引数

body 省略可

レスポンスの本体を定義するオブジェクトです。これは null (既定値)か、以下のうちのいずれかです。

options 省略可

レスポンスに適用したオプションで、カスタム設定したい場合の可能なオプションは、次のとおりです。:

status

このレスポンスのステータスコードです。(例: 200

statusText

ステータスコードに関連付けられたステータスメッセージです(例: OKなど)

headers

レスポンスに追加したいヘッダーです。Headers オブジェクト、または String キー/値ペアのオブジェクトリテラルに含まれています(参考として HTTP ヘッダーをご覧ください)。

Fetch Response の例Fetch Response のライブ版を参照)では、コンストラクターを使用して新しい Response オブジェクトを作成します。その際、新しい Blob を本体として、またカスタム statusstatusText を含む init オブジェクトを渡します。

js
const myBlob = new Blob();
const myOptions = { status: 200, statusText: "SuperSmashingGreat!" };
const myResponse = new Response(myBlob, myOptions);

仕様書

Specification
Fetch Standard
# ref-for-dom-response①

ブラウザーの互換性

BCD tables only load in the browser

関連情報