UNPKG

4.23 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Headers } from './headers';
9import { ResponseOptionsArgs } from './interfaces';
10/**
11 * Creates a response options object to be optionally provided when instantiating a
12 * {@link Response}.
13 *
14 * This class is based on the `ResponseInit` description in the [Fetch
15 * Spec](https://fetch.spec.whatwg.org/#responseinit).
16 *
17 * All values are null by default. Typical defaults can be found in the
18 * {@link BaseResponseOptions} class, which sub-classes `ResponseOptions`.
19 *
20 * This class may be used in tests to build {@link Response Responses} for
21 * mock responses (see {@link MockBackend}).
22 *
23 * @usageNotes
24 * ### Example
25 *
26 * ```typescript
27 * import {ResponseOptions, Response} from '@angular/http';
28 *
29 * var options = new ResponseOptions({
30 * body: '{"name":"Jeff"}'
31 * });
32 * var res = new Response(options);
33 *
34 * console.log('res.json():', res.json()); // Object {name: "Jeff"}
35 * ```
36 *
37 * @deprecated see https://angular.io/guide/http
38 * @publicApi
39 */
40export declare class ResponseOptions {
41 /**
42 * String, Object, ArrayBuffer or Blob representing the body of the {@link Response}.
43 */
44 body: string | Object | ArrayBuffer | Blob | null;
45 /**
46 * Http {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html status code}
47 * associated with the response.
48 */
49 status: number | null;
50 /**
51 * Response {@link Headers headers}
52 */
53 headers: Headers | null;
54 url: string | null;
55 constructor(opts?: ResponseOptionsArgs);
56 /**
57 * Creates a copy of the `ResponseOptions` instance, using the optional input as values to
58 * override
59 * existing values. This method will not change the values of the instance on which it is being
60 * called.
61 *
62 * This may be useful when sharing a base `ResponseOptions` object inside tests,
63 * where certain properties may change from test to test.
64 *
65 * @usageNotes
66 * ### Example
67 *
68 * ```typescript
69 * import {ResponseOptions, Response} from '@angular/http';
70 *
71 * var options = new ResponseOptions({
72 * body: {name: 'Jeff'}
73 * });
74 * var res = new Response(options.merge({
75 * url: 'https://google.com'
76 * }));
77 * console.log('options.url:', options.url); // null
78 * console.log('res.json():', res.json()); // Object {name: "Jeff"}
79 * console.log('res.url:', res.url); // https://google.com
80 * ```
81 */
82 merge(options?: ResponseOptionsArgs): ResponseOptions;
83}
84/**
85 * Subclass of {@link ResponseOptions}, with default values.
86 *
87 * Default values:
88 * * status: 200
89 * * headers: empty {@link Headers} object
90 *
91 * This class could be extended and bound to the {@link ResponseOptions} class
92 * when configuring an {@link Injector}, in order to override the default options
93 * used by {@link Http} to create {@link Response Responses}.
94 *
95 * @usageNotes
96 * ### Example
97 *
98 * ```typescript
99 * import {provide} from '@angular/core';
100 * import {bootstrap} from '@angular/platform-browser/browser';
101 * import {HTTP_PROVIDERS, Headers, Http, BaseResponseOptions, ResponseOptions} from
102 * '@angular/http';
103 * import {App} from './myapp';
104 *
105 * class MyOptions extends BaseResponseOptions {
106 * headers:Headers = new Headers({network: 'github'});
107 * }
108 *
109 * bootstrap(App, [HTTP_PROVIDERS, {provide: ResponseOptions, useClass: MyOptions}]);
110 * ```
111 *
112 * The options could also be extended when manually creating a {@link Response}
113 * object.
114 *
115 * ### Example
116 *
117 * ```
118 * import {BaseResponseOptions, Response} from '@angular/http';
119 *
120 * var options = new BaseResponseOptions();
121 * var res = new Response(options.merge({
122 * body: 'Angular',
123 * headers: new Headers({framework: 'angular'})
124 * }));
125 * console.log('res.headers.get("framework"):', res.headers.get('framework')); // angular
126 * console.log('res.text():', res.text()); // Angular;
127 * ```
128 *
129 * @deprecated see https://angular.io/guide/http
130 * @publicApi
131 */
132export declare class BaseResponseOptions extends ResponseOptions {
133 constructor();
134}
135
\No newline at end of file