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.

48 lines
924 B

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