Created
September 29, 2022 02:01
-
-
Save jimkeller/a1df698c1342e5a798e614eab4b70c2d to your computer and use it in GitHub Desktop.
Basic client service for use with React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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