Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
139 lines (127 sloc) 4.24 KB
description
Making web requests using the XHRService.

Web Requests

Basic requests

A GET request can be made by calling the request method with a URL as the first parameter.

aw.request('https://example.adaptiveweb.io/')
    .then(response => {
        console.log(response);
    });

Specifying request options

Options can be specified as the second parameter. Options can be passed as an Object, or (if using TypeScript) as an instance of XHROptions. Below is the full list of options allowed.

Option name Type Default Description
method string GET

The HTTP method to use when sending the request

Allowed values are GET, POST, DELETE, UPDATE, PATCH or PUT, HEAD

data Blob , string or { [key: string]: any } {} Data to be serialized into the querystring (for GET requests) or body for other methods
async boolean true Whether the request should be sent asynchronously
user string undefined The username for HTTP authorization
password string undefined The password for HTTP authorization
withCredentials boolean false Whether to send cookies to 3rd party domains
timeout number 0 (no timeout) The amount of milliseconds a request can take before automatically being terminated
serialize Function JSON.stringify The method used to serialize data
deserialize Function JSON.parse The method used to deserialize data
headers { [key: string] : string } See notes below
The default headers are:
{
    'Content-Type': 'application/json; charset=utf-8',
    'Accept': 'application/json, text/*'
}

For example, a post request can be made with the following method call:

aw.request('https://example.adaptiveweb.io/', {
    method: 'POST',
    data: {
        myVar: 'value',
        myVar2: 123
    }
}).then(...);
You can’t perform that action at this time.