"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ogcApiRequest = ogcApiRequest;
const request_1 = require("../../../request");
const util_1 = require("../../../util");
const getQueryString_1 = require("./getQueryString");
/**
 * Wrapper over fetch for performing common operations when executing a request to an OGC API, such as:
 * - Creating the query string
 * - URL encoding query string values
 * - Checking whether the response is ok
 * - Returning the .json() of the response body
 *
 * @param url the OGC API endpoint that should actually be hit
 * @param queryParams query params that should be serialized with the request
 * @param options options to customize the search
 * @returns the JSON response from the endpoint
 */
async function ogcApiRequest(url, queryParams, options) {
    const updatedQueryParams = (0, util_1.cloneObject)(queryParams);
    const withQueryString = url + (0, getQueryString_1.getQueryString)(updatedQueryParams);
    // use fetch override if any
    const _fetch = options.requestOptions.fetch || fetch;
    const response = await _fetch(withQueryString, { method: "GET" });
    if (!response.ok) {
        throw new request_1.RemoteServerError(response.statusText, withQueryString, response.status);
    }
    return response.json();
}
//# sourceMappingURL=ogcApiRequest.js.map