Skip to content

Instantly share code, notes, and snippets.

@jimkeller
Created September 29, 2022 02:01
Show Gist options
  • Save jimkeller/a1df698c1342e5a798e614eab4b70c2d to your computer and use it in GitHub Desktop.
Save jimkeller/a1df698c1342e5a798e614eab4b70c2d to your computer and use it in GitHub Desktop.
Basic client service for use with React
import axios from "axios";
import regeneratorRuntime from "regenerator-runtime"; // eslint-disable-line no-unused-vars
const EmployeeDataClient = {
getResults: async(employee_id, endpoint_base_url) => {
endpoint_base_url = "http://localhost:3035/employees"
const response = await axios.get(`${endpoint_base_url}/${employee_id}`)
.catch((err) => {
throw new Error("Error fetching results.");
});
if (typeof(response.results) != 'undefined' && response.results) {
return response.results;
}
else {
throw new Error ("No results key found in response data");
}
}
}
export default EmployeeDataClient;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment