Skip to content

Commit

Permalink
chore(api): add missing fetch utility functions (#5406)
Browse files Browse the repository at this point in the history
### 📣 Summary
Internal addition: add missing `fetchPatchUrl`, `fetchPutUrl`, and
`fetchDeleteUrl` to `api.ts`.
  • Loading branch information
magicznyleszek authored Jan 4, 2025
1 parent e02419e commit 3a15b73
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion jsapp/js/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,46 @@ export const fetchPatch = async <T>(
options?: FetchDataOptions
) => fetchData<T>(path, 'PATCH', data, options);

/** PATCH (update) data to Kobo API at url */
export const fetchPatchUrl = async <T>(
path: string,
data: Json,
options?: FetchDataOptions
) => {
options = Object.assign({}, options, {prependRootUrl: false});
return fetchData<T>(path, 'PATCH', data, options);
};

/** PUT (replace) data to Kobo API at path */
export const fetchPut = async <T>(
path: string,
data: Json,
options?: FetchDataOptions
) => fetchData<T>(path, 'PUT', data, options);

/** DELETE data to Kobo API at path, data is optional */
/** PUT (replace) data to Kobo API at url */
export const fetchPutUrl = async <T>(
path: string,
data: Json,
options?: FetchDataOptions
) => {
options = Object.assign({}, options, {prependRootUrl: false});
return fetchData<T>(path, 'PUT', data, options);
};

/** DELETE something from Kobo API at path, data is optional */
export const fetchDelete = async <T>(
path: string,
data?: Json,
options?: FetchDataOptions
) => fetchData<T>(path, 'DELETE', data, options);

/** DELETE something from Kobo API at url, data is optional */
export const fetchDeleteUrl = async <T>(
path: string,
data?: Json,
options?: FetchDataOptions
) => {
options = Object.assign({}, options, {prependRootUrl: false});
return fetchData<T>(path, 'DELETE', data, options);
};

0 comments on commit 3a15b73

Please sign in to comment.