leumas-universal-crud-react
Version:
Leumas Universal CRUD to a dynamic Endpoint, Setup your own Dynamic Endpoint and Use Leumas API to send to your MONGO clusters
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);
}
};