You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
875 B

  1. import axios from 'axios'
  2. const baseURL = 'http://127.0.0.1:3000/v1' // Todo: change URL by development/staging/production.
  3. export default class ApiService {
  4. constructor() {
  5. this.instance = axios.create({
  6. baseURL
  7. })
  8. }
  9. request(method, url, data = {}, config = {}) {
  10. return this.instance({
  11. method,
  12. url,
  13. data,
  14. ...config
  15. })
  16. .then(response => response.data)
  17. .catch(error => error)
  18. }
  19. get(url, config = {}) {
  20. return this.request('GET', url, config)
  21. }
  22. post(url, data, config = {}) {
  23. return this.request('POST', url, data, config)
  24. }
  25. put(url, data, config = {}) {
  26. return this.request('PUT', url, data, config)
  27. }
  28. patch(url, data, config = {}) {
  29. return this.request('PATCH', url, data, config)
  30. }
  31. delete(url, config = {}) {
  32. return this.request('DELETE', url, {}, config)
  33. }
  34. }