Esta traducción está incompleta. Por favor, ayuda a traducir este artículo del inglés.

La interfaz Response de la Fetch API representa la respuesta a una petición.

Tú puedes crear un nuevo objeto Response usando el  constructorResponse.Response() ,pero es más probable encontrar un objeto Response siendo devuelto como resultado de la operación de otra API, por ejemplo un service worker Fetchevent.respondWith, o un simple GlobalFetch.fetch().

Constructor

Response()
Crea un nuevo objeto Response.

Propiedades

Response.headers Read only
Contiene el objeto Headers asociado con la respuesta.
Response.ok Read only
Contiene un estado indicando si la respuesta fue exitosa (estado en el rango  200-299) o no.
Response.redirected Read only
Indica si la respuesta es o no el resultado de una redirección; eso es, su lista de URL tiene más de una entrada.
Response.status Read only
Contiene el código de estado de la respuesta (e.g., 200 si fue exisitosa).
Response.statusText Read only
Contains the status message corresponding to the status code (e.g., OK for 200).
Response.type Read only
Contains the type of the response (e.g., basic, cors).
Response.url Read only
Contains the URL of the response.
Response.useFinalURL
Contains a boolean stating whether this is the final URL of the response.

Response implements Body, so it also has the following properties available to it:

Body.body Read only
A simple getter used to expose a ReadableStream of the body contents.
Body.bodyUsed Read only
Stores a Boolean that declares whether the body has been used in a response yet.

Methods

Response.clone()
Creates a clone of a Response object.
Response.error()
Returns a new Response object associated with a network error.
Response.redirect()
Creates a new response with a different URL.

Response implements Body, so it also has the following methods available to it:

Body.arrayBuffer()
Takes a Response stream and reads it to completion. It returns a promise that resolves with an ArrayBuffer.
Body.blob()
Takes a Response stream and reads it to completion. It returns a promise that resolves with a Blob.
Body.formData()
Takes a Response stream and reads it to completion. It returns a promise that resolves with a FormData object.
Body.json()
Takes a Response stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as JSON.
Body.text()
Takes a Response stream and reads it to completion. It returns a promise that resolves with a USVString (text).

Examples

In our basic fetch example (run example live) we use a simple fetch() call to grab an image and display it in an <img> tag. The fetch() call returns a promise, which resolves with the Response object associated with the resource fetch operation. You'll notice that since we are requesting an image, we need to run Body.blob (Response implements body) to give the response its correct MIME type.

var myImage = document.querySelector('.my-image');
fetch('flowers.jpg').then(function(response) {
  return response.blob();
}).then(function(blob) {
  var objectURL = URL.createObjectURL(blob);
  myImage.src = objectURL;
});

You can also use the Response.Response() constructor to create your own custom Response object:

var myResponse = new Response();

Specifications

Specification Status Comment
Fetch
La definición de 'Response' en esta especificación.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Soporte básicoChrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39IE Sin soporte NoOpera Soporte completo 29Safari Soporte completo 10.1WebView Android Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference.
Chrome Android Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Mobile Soporte completo SiFirefox Android Soporte completo SiOpera Android Soporte completo 29Safari iOS Soporte completo 10.1Samsung Internet Android Soporte completo 4.0
Response() constructor
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo 15Firefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Soporte completo 10.1WebView Android Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference.
Chrome Android Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Mobile Soporte completo SiFirefox Android Soporte completo SiOpera Android Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari iOS Soporte completo 10.3Samsung Internet Android Soporte completo 4.0
headers
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
ok
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
redirected
Experimental
Chrome Soporte completo 60Edge Soporte completo 16Firefox Soporte completo 49IE Sin soporte NoOpera Soporte completo 47Safari Sin soporte NoWebView Android Soporte completo 60Chrome Android Soporte completo 60Edge Mobile Soporte completo SiFirefox Android Soporte completo 49Opera Android Soporte completo 47Safari iOS Sin soporte NoSamsung Internet Android Sin soporte No
status
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
statusText
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
type
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
url
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
useFinalURL
ExperimentalDeprecated
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
clone
Experimental
Chrome Soporte completo 42
Soporte completo 42
Soporte completo 41
Deshabilitado
Deshabilitado From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Soporte completo SiFirefox Soporte completo 39
Soporte completo 39
Soporte completo 34
Deshabilitado
Deshabilitado From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE Sin soporte NoOpera Soporte completo 29
Soporte completo 29
Soporte completo 28
Deshabilitado
Deshabilitado From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari Sin soporte NoWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile Soporte completo SiFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
error
Experimental
Chrome Soporte completo SiEdge Soporte completo SiFirefox Soporte completo SiIE Sin soporte NoOpera Soporte completo SiSafari Soporte completo SiWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile ? Firefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
redirect
Experimental
Chrome Soporte completo SiEdge Soporte completo SiFirefox Soporte completo SiIE Sin soporte NoOpera Soporte completo SiSafari Soporte completo SiWebView Android Sin soporte NoChrome Android Sin soporte NoEdge Mobile ? Firefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
trailerChrome ? Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?

Leyenda

Soporte completo  
Soporte completo
Sin soporte  
Sin soporte
Compatibility unknown  
Compatibility unknown
Experimental. Esperar que el comportamiento cambie en el futuro.
Experimental. Esperar que el comportamiento cambie en el futuro.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
El usuario debe de habilitar explícitamente esta característica.
El usuario debe de habilitar explícitamente esta característica.

See also

Etiquetas y colaboradores del documento

Colaboradores en esta página: crrlos
Última actualización por: crrlos,