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

Function apiRequest

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

Source from the content-addressed store, hash-verified

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