Help Angular by taking a 1 minute survey!Go to surveyHome

BaseRequestOptions

Subclass of RequestOptions, with default values.

See more...

Deprecated: see https://angular.io/guide/http

      
      class BaseRequestOptions extends RequestOptions {

  // inherited from http/RequestOptions
  constructor(opts: RequestOptionsArgs = {})
  method: RequestMethod | string | null
  headers: Headers | null
  body: any
  url: string | null
  params: URLSearchParams
  search: URLSearchParams
  withCredentials: boolean | null
  responseType: ResponseContentType | null
  merge(options?: RequestOptionsArgs): RequestOptions
}
    

Description

Default values:

This class could be extended and bound to the RequestOptions class when configuring an Injector, in order to override the default options used by Http to create and send Requests.

import {BaseRequestOptions, RequestOptions} from '@angular/http'; class MyOptions extends BaseRequestOptions { search: string = 'coreTeam=true'; } {provide: RequestOptions, useClass: MyOptions};
      
      import {BaseRequestOptions, RequestOptions} from '@angular/http';

class MyOptions extends BaseRequestOptions {
  search: string = 'coreTeam=true';
}

{provide: RequestOptions, useClass: MyOptions};
    

The options could also be extended when manually creating a Request object.

import {BaseRequestOptions, Request, RequestMethod} from '@angular/http'; const options = new BaseRequestOptions(); const req = new Request(options.merge({ method: RequestMethod.Post, 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
      
      import {BaseRequestOptions, Request, RequestMethod} from '@angular/http';

const options = new BaseRequestOptions();
const req = new Request(options.merge({
  method: RequestMethod.Post,
  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