Http

Collection of HTTP functions.

Methods

request

request(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP Request. Can be used to post or get data to and from a URL.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.request('http://www.example.com/data.json')        // GET data from a URL
Http.request('http://www.example.com/api/person', {     // POST data to a URL
  method: 'post',
  headers: {
    'X-Auth-Token': 'secret_token'
  },
  data: {
    firstName: 'John',
    age: 30
  }
})
Http.request('http://www.example.com/api/big-data', {   // POST, but don't wait for result
  wait: false,
  method: 'post',
  data: {}
})

all

all(requests: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
}[])

Create multiple parallel HTTP requests and returns when all responses have been received. Responses are returned in an array in the same order as the requests.

Parameters

requests { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}[]

Array of requests. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }[]

Examples

Http.all([
  { url: 'http://www.example.com/data.json' }
  { url: 'http://www.example.com/api/add', method: 'post', data: { a: 1, b: 2 } }
])

get

get(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP GET Request.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.get('http://www.example.com/data.json')

post

post(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP POST Request.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.post('http://www.example.com/data.json')
Http.post('http://www.example.com/api/person', {
  data: {
    firstName: 'John',
    age: 30
  }
})

put

put(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP PUT Request.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.put('http://www.example.com/data.json')
Http.put('http://www.example.com/api/person', {
  data: {
    firstName: 'John',
    age: 31
  }
})

delete

delete(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP DELETE Request.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.delete('http://www.example.com/data.json')
head(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP HEAD Request.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.head('http://www.example.com/data.json')

patch

patch(url: string, options?: {
    method?: any,
    headers?: Record<string, string>,
    data?: any,
    wait?: boolean,
    url?: string,
    baseURL?: string,
    params?: any,
    timeout?: number,
    withCredentials?: boolean,
    auth?: any,
    responseType?: string,
    responseEncoding?: string,
    xsrfCookieName?: string,
    xsrfHeaderName?: string,
    maxContentLength?: number,
    maxBodyLength?: number,
    maxRedirects?: number,
    proxy?: any,
    decompress?: boolean, 
    httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }
})

Create a HTTP PATCH Request.

Parameters

url string

The URL.

options { method?: any, headers?: Record<string, string>, data?: any, wait?: boolean, url?: string, baseURL?: string, params?: any, timeout?: number, withCredentials?: boolean, auth?: any, responseType?: string, responseEncoding?: string, xsrfCookieName?: string, xsrfHeaderName?: string, maxContentLength?: number, maxBodyLength?: number, maxRedirects?: number, proxy?: any, decompress?: boolean, httpsAgent?: { ca?: string, key?: string, cert?: string, pfx?: string, ciphers?: string, passphrase?: string }}

(optional) Options object - set headers, method and other properties. More information

Return type

{ data: any, status: number, statusText: string, headers: Record<string, string>, error?: string }

Examples

Http.patch('http://www.example.com/data.json')

Last updated