# give/4.16.9/src/Log/Admin/Logs/api.js

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.9. 50 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/Log/Admin/Logs/api.js
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/Log/Admin/Logs/api.js
- Modified: 2026-09-03T18:44:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.9/code/src/Log/Admin/Logs/api.js#L10-L20`.

```javascript
import apiFetch from '@wordpress/api-fetch';
import useSWR from 'swr';

const NAMESPACE = '/give-api/v2/logs';

/**
 * @since 4.16.8 Replaced axios with @wordpress/api-fetch, which resolves with the parsed
 *            response body and supplies the REST root and nonce from WordPress core.
 */
const API = {
    get: (endpoint) => apiFetch({path: NAMESPACE + endpoint}),
    post: (endpoint, data) => apiFetch({path: NAMESPACE + endpoint, method: 'POST', data}),
    delete: (endpoint) => apiFetch({path: NAMESPACE + endpoint, method: 'DELETE'}),
};

export default API;

// SWR Fetcher
export const Fetcher = (endpoint) =>
    API.get(endpoint).then(({data, ...rest}) => {
        return {
            data,
            response: rest,
        };
    });

export const useLogFetcher = (endpoint, params = {}) => {
    const {data, error} = useSWR(endpoint, Fetcher, params);
    return {
        data: data ? data.data : undefined,
        isLoading: !error && !data,
        isError: error,
        response: data ? data.response : undefined,
    };
};

/**
 * GET endpoint with additional parameters.
 *
 * @since 4.16.8 apiFetch's root URL middleware rewrites the separator on sites without
 *            pretty permalinks, so the endpoint always uses '?' here.
 */
export const getEndpoint = (endpoint, data) => {
    if (data) {
        return endpoint + '?' + new URLSearchParams(data).toString();
    }

    return endpoint;
};

```
