ResponseOptions
class deprecated
Creates a response options object to be optionally provided when instantiating a Response.
Deprecated: see https://angular.io/guide/http
class ResponseOptions {
constructor(opts: ResponseOptionsArgs = {})
body: string | Object | ArrayBuffer | Blob | null
status: number | null
headers: Headers | null
url: string | null
merge(options?: ResponseOptionsArgs): ResponseOptions
} Subclasses
Description
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).
Constructor
|
| opts | Type: Optional. Default is |
Properties
| Property | Description |
|---|---|
body: string | Object | ArrayBuffer | Blob | null | String, Object, ArrayBuffer or Blob representing the body of the |
status: number | null | Http status code associated with the response. |
headers: Headers | null | Response headers |
url: string | null |
Methods
| merge() | ||
|---|---|---|
| Creates a copy of the | ||
|
| options | Type: Optional. Default is |
Returns
This may be useful when sharing a base ResponseOptions object inside tests, where certain properties may change from test to test.
Example
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 Usage notes
Example
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"}
© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v6.angular.io/api/http/ResponseOptions