UNPKG

@soleil-se/app-util

Version:

Utility functions for WebApps, RESTApps and Widgets in Sitevision.

24 lines (23 loc) 1.22 kB
/** * Fetches JSON data from a specified URI. * URI:s starting with `/rest-api`, `/appresource`, `/edit-app-config` or a protocol, for example * `https://` will be left as is. Other URI:s willbe converted to match a route in the current app * with `getRouteUri`. * * @param {string} uri - The URI to fetch JSON data from. * @param {object} options - The options for the fetch request, see <https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters>. * @param {string} options.method - The HTTP method to use in the request. * @param {object} options.params - The parameters to be included in the request URL. * @param {object} options.body - The body to include in the request. * @param {number} options.retries - The number of retries to attempt in case of a timeout error. * @param {object} options.headers - The headers to be included in the request. * @returns {Promise<object>} A promise that resolves to the JSON response. * @throws {Error} If the response is not successful or cannot be parsed as JSON. */ export default function fetchJson(uri: string, options?: { method: string; params: object; body: object; retries: number; headers: object; }): Promise<object>;