Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): Promise {
// Ensure there is a final slash
const baseUrl = api.replace(/\/?$/, "/");
// Add the REST path depending on whether it should start
// with "/wp/v2" or not
const requestUrl =
isWpCom || endpoint.startsWith("/")
? `${baseUrl}${endpoint.replace(/^\//, "")}`
: `${baseUrl}wp/v2/${endpoint}`;
// Add query parameters
const query = stringify(params, { arrayFormat: "bracket", encode: false });
// Send request
return fetch(`${requestUrl}${query && "?"}${query}`);
}