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

Http

Http request object. Expose chainable API

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

Method Summary

Public Methods
public

body(body: Object): Object

Adds body to request model

public

bodyProcessor(bodyProcessor: func): Object

Sets the function which gets the body object as a parameter which result would be used as a request body

public

Executes HTTP request

public

executor(executor: function(url: string, method: string, headers: string[], responseType: string, body: Object): Promise): Object

Set the middleware that will perform the request

public

header(header: string, value: string): Object

Adds header to request model

public

method(method: string): Object

Adds HTTP method information to request model

public

query(name: string, value: string): Object

Adds query string param

public

responseProcessor(responseProcessor: func): Object

Sets the function which gets the response and produces another value Useful for default HTTP error handling

public

responseType(responseType: string): Object

Sets response content type Proper values could be obtained form XmlHttpRequest specification https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Properties

public

segment(segment: string, value: string): Object

Adds dynamic segment value

public

url(url: string): Object

Adds URL information to HTTP request model

Public Constructors

public constructor(params: HttpRequestParams) source

Params:

NameTypeAttributeDescription
params HttpRequestParams

HTTP request params

Public Members

public internals: * source

Public Methods

public body(body: Object): Object source

Adds body to request model

Params:

NameTypeAttributeDescription
body Object

request payload

Return:

Object

Http object

public bodyProcessor(bodyProcessor: func): Object source

Sets the function which gets the body object as a parameter which result would be used as a request body

Params:

NameTypeAttributeDescription
bodyProcessor func

f(x) => valid_http_body

Return:

Object

Http object

public exec(): Object source

Executes HTTP request

Return:

Object

Promise

public executor(executor: function(url: string, method: string, headers: string[], responseType: string, body: Object): Promise): Object source

Set the middleware that will perform the request

Params:

NameTypeAttributeDescription
executor function(url: string, method: string, headers: string[], responseType: string, body: Object): Promise

function which performs the request asynchroniously and returns Promise back

Return:

Object

Http object

public header(header: string, value: string): Object source

Adds header to request model

Params:

NameTypeAttributeDescription
header string

valid header key

value string

valid header value

Return:

Object

Http object

public method(method: string): Object source

Adds HTTP method information to request model

Params:

NameTypeAttributeDescription
method string

HTTP method

Return:

Object

Http object

public query(name: string, value: string): Object source

Adds query string param

Params:

NameTypeAttributeDescription
name string

param key

value string

param value

Return:

Object

Http object

public responseProcessor(responseProcessor: func): Object source

Sets the function which gets the response and produces another value Useful for default HTTP error handling

Params:

NameTypeAttributeDescription
responseProcessor func

f(x) => y

Return:

Object

Http object

Example:

response => {
 switch(response.code) {
   case "404":
     return { message: 'Resource not found' }
 }
}

public responseType(responseType: string): Object source

Sets response content type Proper values could be obtained form XmlHttpRequest specification https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Properties

Params:

NameTypeAttributeDescription
responseType string

Proper values could be obtained form XmlHttpRequest specification https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Properties

Return:

Object

Http object

public segment(segment: string, value: string): Object source

Adds dynamic segment value

Params:

NameTypeAttributeDescription
segment string

segment key

value string

segment value

Return:

Object

Http object

public url(url: string): Object source

Adds URL information to HTTP request model

Params:

NameTypeAttributeDescription
url string

URL

Return:

Object

Http object