This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Response: Response() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2017년 3월⁩.

참고 : 이 기능은 Web Worker에서 사용할 수 있습니다.

Response() 생성자는 새로운 Response 객체를 생성합니다.

구문

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

매개변수

body Optional

응답의 본문을 정의하는 객체입니다. 기본값은 null이며, 다음 중 하나일 수 있습니다.

options Optional

응답에 적용할 사용자 정의 설정을 포함하는 옵션 객체이거나, 빈 객체(기본값)입니다. 가능한 옵션은 다음과 같습니다.

status

응답의 상태 코드입니다. 기본값은 200입니다.

statusText

상태 코드와 관련된 상태 메시지로, 예를 들어 "OK"와 같습니다. 기본값은 ""입니다.

headers

응답에 추가할 헤더를 정의합니다. Headers 객체이거나, String 키/값 쌍의 객체 리터럴일 수 있습니다. HTTP 헤더 문서를 참조하세요. 기본값은 비어 있습니다.

예제

Fetch Response 예제 (Fetch Response 실시간 보기)에서는 생성자를 사용해 새로운 Response 객체를 생성합니다. 이때 본문으로 새 Blob 을 전달하고, 사용자 지정 statusstatusText를 포함한 초기화 객체를 함께 전달합니다.

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

명세서

Specification
Fetch
# ref-for-dom-response①

브라우저 호환성

같이 보기