Skip to content

Instantly share code, notes, and snippets.

@brybrophy
Last active October 26, 2017 20:35
Show Gist options
  • Save brybrophy/da16d78de7f7e56158837c1abcf52669 to your computer and use it in GitHub Desktop.
Save brybrophy/da16d78de7f7e56158837c1abcf52669 to your computer and use it in GitHub Desktop.
import axios from 'axios';
import { displayUserFeedback } from './utils';
export function handleClickGetAllUsers() {
axios.get('https://www.example.org/api/users', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
timeout: 15000
})
.then(res => {
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 function handleClickGetOneUser(userId) {
axios.get(`https://www.example.org/api/users/${usersId}`, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
timeout: 15000
})
.then(res => {
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