Home Reference Source Repository
import Http from 'rx-http/src/http.js'
public class | source

Http

An HTTP client.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Method Summary

Public Methods
public
public
public

delete(url: String, opts: Object): Request

public

get(url: String, opts: Object): Request

public

head(url: string, opts: Object): Request

public
public

options(url: String, opts: Object): Request

public

password(value: String): String | Http

public

patch(url: String, opts: Object): Request

public

post(url: String, opts: Object): Request

public

put(url: String, opts: Object): Request

public
public

request(url: String, options: Object): Request

public

timeout(value: Number): Number | Http

public

trace(url: String, opts: Object): Request

public

user(value: String): String | Http

public
public
public

Public Constructors

public constructor(options: Object) source

Params:

NameTypeAttributeDescription
options Object
  • optional

A hash of settings for this client.

Public Methods

public addInterceptor(interceptor: Interceptor): Http source

Params:

NameTypeAttributeDescription
interceptor Interceptor

Add the interceptor to the end of the chain of interceptors.

Return:

Http

The current client instance.

public baseUrl(url: String | Http): String | Http source

Params:

NameTypeAttributeDescription
url String | Http
  • optional

the base URL applied by default to all requests from this client.

Return:

String | Http

If url is specified, updates the default baseUrl for all requests created with this client, and returns the client instance. If value is ommitted, returns the current baseUrl.

public delete(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).delete('/some/stuff', {
  retries: 2,
  timeout: 10000
})

public get(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).get('/some/stuff', {
  retries: 2
  timeout: 10000
})

public head(url: string, opts: Object): Request source

Params:

NameTypeAttributeDescription
url string

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).head('/some/stuff', {
  retries: 2,
  timeout: 10000
})

public interceptors(values: Interceptor[]): Interceptor[] | Http source

Params:

NameTypeAttributeDescription
values Interceptor[]
  • optional

An array of interceptors.

Return:

Interceptor[] | Http

If values is specified, replaces the default interceptors for all requests from this client, and returns the client instance. If values is ommitted, returns the current array of interceptors.

public options(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).head('/some/stuff', {
  retries: 2,
  timeout: 10000
})

public password(value: String): String | Http source

Params:

NameTypeAttributeDescription
value String
  • optional

Basic auth password

Return:

String | Http

If the value is specified, sets the password and returns the current Http. If value is ommitted, returns the current password.

public patch(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).patch('/some/stuff', {
  body: { foo: "bar", baz: 1 },
  timeout: 10000
})

public post(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).post('/some/stuff', {
  body: { foo: "bar", baz: 1 },
  timeout: 10000
})

public put(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).put('/some/stuff', {
  body: { foo: "bar", baz: 1 },
  timeout: 10000
})

public removeInterceptor(interceptor: Interceptor): Http source

Params:

NameTypeAttributeDescription
interceptor Interceptor

Remove the interceptor from the chain of interceptors.

Return:

Http

The current client instance.

public request(url: String, options: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

options Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).request('/some/stuff', {
  method: 'POST',
  body: { foo: "bar", baz: 1 },
  timeout: 10000
})

public timeout(value: Number): Number | Http source

Params:

NameTypeAttributeDescription
value Number
  • optional

The request timeout in milliseconds

Return:

Number | Http

If value is specified, updates the default request timeout for all requests created with this client, and returns the client instance. If value is ommitted, returns the current timeout value.

public trace(url: String, opts: Object): Request source

Params:

NameTypeAttributeDescription
url String

the URL where the request will be sent.

opts Object
  • optional

add/override settings for this request.

Return:

Request

Example:

new Http({ baseUrl: 'http://mydomain.com', timeout: 5000 }).trace('/some/stuff', {
  retries: 2,
  timeout: 10000
})

public user(value: String): String | Http source

Params:

NameTypeAttributeDescription
value String
  • optional

Basic auth username

Return:

String | Http

If the value is specified, sets the username and returns the current Http. If value is ommitted, returns the current username.

public withCredentials(value: Boolean): Boolean | Http source

Params:

NameTypeAttributeDescription
value Boolean
  • optional

Flag indicating whether cross-site AccessControl requests should be made using cookies, authorization headers, or TLS client certificates. More detail: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

Return:

Boolean | Http

If the value is specified, sets the withCredentials flag and returns the current Http. If value is ommitted, returns the current value of the flag.

public xsrfCookieName(value: String): String | Http source

Params:

NameTypeAttributeDescription
value String
  • optional

The name of the XSRF cookie

Return:

String | Http

If the value is specified, sets the name of the XSRF Cookie and returns the current Http. If value is ommitted, returns the current name.

public xsrfHeaderName(value: String): String | Http source

Params:

NameTypeAttributeDescription
value String
  • optional

The name of the XSRF header

Return:

String | Http

If the value is specified, sets the name of the XSRF Header and returns the current Http. If value is ommitted, returns the current name.