Last active
October 26, 2017 20:34
-
-
Save brybrophy/1867689b86b866ef5f23ec65464f1a7f to your computer and use it in GitHub Desktop.
This file contains 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 { displayUserFeedback } from './utils'; | |
const axiosConfig = { | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
timeout: 15000 | |
}; | |
const basePath = 'https://www.example.org/api/users'; | |
export async function handleClickGetAllUsers() { | |
try { | |
const res = await axios.get(basePath, axiosConfig); | |
return res.data; | |
} catch () { | |
// This is just a hypothetical utility function to display a toast | |
// notification to the user in the event of an error. | |
displayUserFeedback('There was an error retrieving the users.'); | |
} | |
} | |
export async function handleClickGetOneUser(userId) { | |
try { | |
const res = await axios.get(`${basePath}/${userId}`, axiosConfig); | |
return res.data; | |
} catch () { | |
displayUserFeedback('There was an error retrieving the user.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment