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.

42 lines
855 B

  1. import axios from 'axios'
  2. axios.defaults.xsrfCookieName = 'csrftoken'
  3. axios.defaults.xsrfHeaderName = 'X-CSRFToken'
  4. class ApiService {
  5. constructor() {
  6. this.instance = axios.create({
  7. baseURL: process.env.baseUrl
  8. })
  9. }
  10. request(method, url, data = {}, config = {}) {
  11. return this.instance({
  12. method,
  13. url,
  14. data,
  15. ...config
  16. })
  17. }
  18. get(url, config = {}) {
  19. return this.request('GET', url, {}, config)
  20. }
  21. post(url, data, config = {}) {
  22. return this.request('POST', url, data, config)
  23. }
  24. put(url, data, config = {}) {
  25. return this.request('PUT', url, data, config)
  26. }
  27. patch(url, data, config = {}) {
  28. return this.request('PATCH', url, data, config)
  29. }
  30. delete(url, data = {}, config = {}) {
  31. return this.request('DELETE', url, data, config)
  32. }
  33. }
  34. export default new ApiService()