service.js 668 B

1234567891011121314151617181920212223242526272829303132333435
  1. function HttpService(apiUrl) {
  2. this.getAllStudents = function() {
  3. return $.ajax({
  4. url: `${apiUrl}/students`,
  5. method: 'GET'
  6. });
  7. // $.get(`${api}/students`);
  8. };
  9. this.getStudentById = function(id) {
  10. return $.ajax({
  11. url: `${apiUrl}/students/${id}`,
  12. method: 'GET'
  13. });
  14. };
  15. this.updateStudentsById = function(id, data) {
  16. return $.ajax({
  17. url: `${apiUrl}/students/${id}`,
  18. method: 'PUT',
  19. data: data
  20. });
  21. };
  22. this.deleteStudentById = function(id) {
  23. return $.ajax({
  24. url: `${apiUrl}/students/${id}`,
  25. method: 'DELETE'
  26. });
  27. };
  28. this.postStudentsById = function(data) {
  29. return $.ajax({
  30. url: `${apiUrl}/students`,
  31. method: 'POST',
  32. data: data
  33. });
  34. };
  35. }