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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

{ data: any, status: number, statusText: string, headers: Record<string, 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: {}
})

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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

{ data: any, status: number, statusText: string, headers: Record<string, 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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

{ data: any, status: number, statusText: string, headers: Record<string, 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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

{ data: any, status: number, statusText: string, headers: Record<string, 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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

{ data: any, status: number, statusText: string, headers: Record<string, 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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

{ data: any, status: number, statusText: string, headers: Record<string, 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 }, [x: any]: unknown  }) 

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 }, [x: any]: unknown }

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

Return type

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

Examples

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