Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import axios from 'axios';
  2.  
  3. const RootPath = 'http://192.168.100.11:5000';
  4. const RootPathTwo = 'https://api.myjson.com';
  5.  
  6. const Get = path => {
  7. const promise = new Promise((resolve, reject) => {
  8. axios.get(`${RootPath}/${path}`).then(
  9. response => {
  10. resolve(response.data);
  11. },
  12. err => {
  13. reject(err);
  14. },
  15. );
  16. });
  17. return promise;
  18. };
  19.  
  20. const GetTwo = path => {
  21. const promise = new Promise((resolve, reject) => {
  22. axios.get(`${RootPathTwo}/${path}`).then(
  23. result => {
  24. resolve(result.data);
  25. },
  26. err => {
  27. reject(err);
  28. },
  29. );
  30. });
  31. return promise;
  32. };
  33.  
  34. const Post = (path, data) => {
  35. const promise = new Promise((resolve, reject) => {
  36. axios.post(`${RootPath}/${path}`, data).then(
  37. result => {
  38. resolve(result);
  39. },
  40. err => {
  41. reject(err);
  42. },
  43. );
  44. });
  45. return promise;
  46. };
  47.  
  48. // get
  49. const getData = () => Get('api/jobs');
  50. const getProfile = () => Get('api/profile');
  51. const getResetPassword = data => Get('api/api/driver/users/reset/' + data);
  52. const getNotification = () => GetTwo('bins/1cmvll');
  53.  
  54. // post
  55. const postLogin = data => Post('api/driver/users/login', data);
  56. const postRegister = data => Post('api/driver/users/create', data);
  57. const postForgotPassword = data => Post('api/driver/users/forgot', data);
  58. const postResetPassword = (url, data) =>
  59. Post('api/driver/users/reset/' + url, data);
  60. const API = {
  61. getData,
  62. getProfile,
  63. getNotification,
  64. getResetPassword,
  65. postLogin,
  66. postRegister,
  67. postForgotPassword,
  68. postResetPassword,
  69. };
  70.  
  71. export default API;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement