Skip to content

Instantly share code, notes, and snippets.

@dbshoupe
Last active October 2, 2021 16:07
Show Gist options
  • Select an option

  • Save dbshoupe/2c52a8145fbf811b8b7f1408f7be1858 to your computer and use it in GitHub Desktop.

Select an option

Save dbshoupe/2c52a8145fbf811b8b7f1408f7be1858 to your computer and use it in GitHub Desktop.

Revisions

  1. dbshoupe renamed this gist Nov 14, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. dbshoupe renamed this gist Nov 14, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. dbshoupe created this gist Nov 14, 2017.
    42 changes: 42 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    import axios from 'axios';
    import store from "@/data/state"

    class Http {

    constructor() {
    let service = axios.create({});
    service.interceptors.request.use((config) => {
    config.headers.common['x-access-token'] = store.state.token
    return config
    })
    this.service = service;
    }

    redirectTo = (document, path) => {
    document.location = path
    }

    get(path) {
    return this.service.get(path)
    }

    patch(path, payload, callback) {
    return this.service.request({
    method: 'PATCH',
    url: path,
    responseType: 'json',
    data: payload
    }).then((response) => callback(response.status, response.data));
    }

    post(path, payload) {
    return this.service.request({
    method: 'POST',
    url: path,
    responseType: 'json',
    data: payload
    })
    }
    }

    export default new Http;