W3cubDocs

/Angular 4 TypeScript

ResponseOptions

Experimental Class

Class Overview

class ResponseOptions {
  constructor({body, status, headers, statusText, type, url}?: ResponseOptionsArgs)
  
  
  body : string|Object|ArrayBuffer|Blob
  status : number
  headers : Headers
  url : string
  merge(options?: ResponseOptionsArgs) : ResponseOptions
}

Class Description

Creates a response options object to be optionally provided when instantiating a Response.

This class is based on the ResponseInit description in the Fetch Spec.

All values are null by default. Typical defaults can be found in the BaseResponseOptions class, which sub-classes ResponseOptions.

This class may be used in tests to build Responses for mock responses (see MockBackend).

Example (live demo)

import {ResponseOptions, Response} from '@angular/http';

var options = new ResponseOptions({
  body: '{"name":"Jeff"}'
});
var res = new Response(options);

console.log('res.json():', res.json()); // Object {name: "Jeff"}

Constructor

constructor({body, status, headers, statusText, type, url}?: ResponseOptionsArgs)

Class Details

body : string|Object|ArrayBuffer|Blob

String, Object, ArrayBuffer or Blob representing the body of the Response.

status : number

Http status code associated with the response.

headers : Headers

Response headers

url : string
merge(options?: ResponseOptionsArgs) : ResponseOptions

Creates a copy of the ResponseOptions instance, using the optional input as values to override existing values. This method will not change the values of the instance on which it is being called.

This may be useful when sharing a base ResponseOptions object inside tests, where certain properties may change from test to test.

(live demo)

import {ResponseOptions, Response} from '@angular/http';

var options = new ResponseOptions({
  body: {name: 'Jeff'}
});
var res = new Response(options.merge({
  url: 'https://google.com'
}));
console.log('options.url:', options.url); // null
console.log('res.json():', res.json()); // Object {name: "Jeff"}
console.log('res.url:', res.url); // https://google.com

exported from http/index, defined in http/src/base_response_options.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/docs/ts/latest/api/http/index/ResponseOptions-class.html