RequestOptions
Experimental Class
Обзор класса
class RequestOptions {
constructor({method, headers, body, url, search, withCredentials,
responseType}?: RequestOptionsArgs)
method : RequestMethod|string
headers : Headers
body : any
url : string
search : URLSearchParams
withCredentials : boolean
responseType : ResponseContentType
merge(options?: RequestOptionsArgs) : RequestOptions
}
Описание класса
Создаёт объект параметров запроса, который можно при необходимости передать при инициализации Request.
Этот класс основан на описании RequestInit в Спецификации Fetch.
Все значения по умолчанию равны null. Типичные значения по умолчанию можно найти в классе BaseRequestOptions, который является подклассом RequestOptions.
Пример (живая демонстрация)
import {RequestOptions, Request, RequestMethod} from '@angular/http';
var options = new RequestOptions({
method: RequestMethod.Post,
url: 'https://google.com'
});
var req = new Request(options);
console.log('req.method:', RequestMethod[req.method]); // Post
console.log('options.url:', options.url); // https://google.com
Конструктор
constructor({method, headers, body, url, search, withCredentials,
responseType}?: RequestOptionsArgs) Подробное описание класса
method : RequestMethod|string
Метод HTTP, с помощью которого выполняется Request. Допустимые методы определены в перечислении RequestMethod.
headers : Headers
Headers, которые нужно прикрепить к Request.
body : any
Тело, которое нужно использовать при создании Request.
url : string
URL, с помощью которого выполняется Request.
search : URLSearchParams
Параметры поиска, которые нужно включить в Request.
withCredentials : boolean
Включить использование учетных данных для Request.
responseType : ResponseContentType
merge(options?: RequestOptionsArgs) : RequestOptions
Создаёт копию экземпляра RequestOptions, используя необязательные входные данные для переопределения существующих значений. Этот метод не изменяет значения экземпляра, на котором он вызывается.
Обратите внимание, что headers и search полностью переопределят существующие значения, если они присутствуют в объекте options. Если эти значения должны быть объединены, это следует сделать перед вызовом merge на экземпляре RequestOptions.
import {RequestOptions, Request, RequestMethod} from '@angular/http';
var options = new RequestOptions({
method: RequestMethod.Post
});
var req = new Request(options.merge({
url: 'https://google.com'
}));
console.log('req.method:', RequestMethod[req.method]); // Post
console.log('options.url:', options.url); // null
console.log('req.url:', req.url); // https://google.com
экспортировано из @angular/http/index, определено в @angular/http/src/base_request_options.ts
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v2.angular.io/docs/ts/latest/api/http/index/RequestOptions-class.html