ogcApiRequest

Function

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
  • Appending the ?target query param if needed
  • Checking whether the response is ok
  • Returning the .json() of the response body

Note: the ?target query param is only appended if the target site (options.site) is different from the the site that will have its OGC API hit (url). This allows us to use the environment-level OGC API's url while actually targeting a specific Hub Site's catalog. It's a powerful capability that significantly eases local development.

Example: https://hubqa.arcgis.com/api/search/v1?target="my-actual-hub.hub.arcgis.com"

We omit the ?target query when the site and url are the same because it would be redundant.

Bad example: https://hubqa.arcgis.com/api/search/v1?target="hubqa.arcgis.com" Good example: https://hubqa.arcgis.com/api/search/v1

  • ogcApiRequest(url: string, queryParams: Record<stringany>, options: IHubSearchOptions) : Promise<any>

Parameters

Parameter Type Default Notes
url Required string

the OGC API endpoint that should actually be hit

queryParams Required Record<stringany>

query params that should be serialized with the request (excluding target)

options Required IHubSearchOptions

options to customize the search, such as the site whose catalogs we're targeting

Returns

the JSON response from the endpoint

Promise<any>

Function defined in common/src/search/_internal/hubSearchItemsHelpers/ogcApiRequest.ts:30