Skip to main content

getDefaultRequestConfig

getDefaultRequestConfig returns the default configuration object we use when making requests with fetch(). It sets a POST method along with sensible Accept and Content-Type headers.

It's used internally by fetchJSON, but you can also call it directly and spread/merge your own overrides on top when building a bespoke request.

The optional type argument (default 'json') controls the Accept header — e.g. passing 'javascript' produces Accept: application/javascript.

info

Currently the default method provided by getDefaultRequestConfig is POST, so GET must be specified for GET requests

Usage examples

Basic

window.BAO.utils.getDefaultRequestConfig()
// {
// method: 'POST',
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
// }

Merging in your own options

const config = {
...window.BAO.utils.getDefaultRequestConfig(),
method: 'GET'
}

fetch('/cart.js', config)