leumas-private-shared
Version:
Private React JSX Package For Leumas Shared Components, Headers, Footers, Asides, Login Pages, API Key Manager and much more. Styles and everything reusable to avoid DRY code across all of our subdomains
20 lines (18 loc) • 722 B
JSX
// runEndpoint.jsx
import axios from 'axios';
/**
* Runs a single endpoint request.
* @param {string} endpoint - The API endpoint for sending the request.
* @param {object} requestData - The request data.
* @param {function} onSuccess - Callback function to handle success.
* @param {function} onError - Callback function to handle error.
*/
export const runEndpoint = async (endpoint, requestData, onSuccess, onError) => {
try {
const response = await axios.post(endpoint, [requestData]); // Wrapping the single endpoint in an array
onSuccess(response.data);
} catch (error) {
console.error("Error running the endpoint:", error);
onError(error);
}
};