MCPcopy Create free account
hub / github.com/decaporg/decap-cms / apiRequest

Function apiRequest

packages/decap-cms-lib-util/src/API.ts:195–218  ·  view source on GitHub ↗
(
  path: string,
  config: RequestConfig,
  parser = (response: Response) => parseResponse(response),
)

Source from the content-addressed store, hash-verified

193}
194
195export async function apiRequest(
196 path: string,
197 config: RequestConfig,
198 parser = (response: Response) => parseResponse(response),
199) {
200 const { token, backend, ...props } = config;
201 const options = { cache: 'no-cache', ...props };
202 const headers = await constructRequestHeaders({ headers: options.headers || {}, token });
203 const baseUrl = config.apiRoot ?? apiRoots[backend];
204 const url = constructUrlWithParams(`${baseUrl}${path}`, options.params);
205 let responseStatus = 500;
206 try {
207 const req = unsentRequest.fromFetchArguments(url, {
208 ...options,
209 headers,
210 }) as unknown as ApiRequest;
211 const response = await requestWithBackoff(api, req);
212 responseStatus = response.status;
213 const parsedResponse = await parser(response);
214 return parsedResponse;
215 } catch (error) {
216 return handleRequestError(error, responseStatus, backend);
217 }
218}
219
220export async function getDefaultBranchName(configs: {
221 backend: Backend;

Callers 1

getDefaultBranchNameFunction · 0.85

Calls 5

constructRequestHeadersFunction · 0.85
constructUrlWithParamsFunction · 0.85
requestWithBackoffFunction · 0.85
handleRequestErrorFunction · 0.85
parseResponseFunction · 0.70

Tested by

no test coverage detected