Menu

Request

The Request class is a light wrapper around XMLHttpRequest which allows you to easily make GET or POST requests. By default the Content-Type is JSON but this can be overridden. Each method returns a promise which resolves to the exact response passed to the XHR load event.

Methods

get(url, options) #

Make a GET request to the specified URL.

Options has the following format

{
    headers: {
        Content-Type: 'application/json'
    },
    query: {
        hello: 'world',
        foo: 'bar'
    }
}

Example

const params = {
    query: {
        sort: 'age'
    }
}
const response = await Request.get('https://app.mobify.com/api/users', params)
console.log(response)

post(url, body, options) #

Make a POST request to the specified URL

Example

const body = {
    foo: 'bar'
}
const params = {
    headers: {
        Authentication: 'Bearer 1234567890'
    }
}
const response = await Request.post('https://app.mobify.com/api/product', body, params)
console.log(response)