Created
July 26, 2021 12:26
-
-
Save odeke/c5b69878dfda61edf796a8d6c896aad3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Config from "./Config"; | |
| import axios from 'axios'; | |
| export default class ApiManager { | |
| static myInstance = null; | |
| // _token = ""; | |
| /** | |
| * @returns {ApiManager} | |
| */ | |
| static getInstance() { | |
| if (ApiManager.myInstance == null) { | |
| ApiManager.myInstance = new ApiManager(); | |
| ApiManager.myInstance.initAxios(); | |
| } | |
| return this.myInstance; | |
| } | |
| initAxios(){ | |
| this.myInstance = axios.create({ | |
| baseURL: Config.server_url, | |
| }); | |
| } | |
| setToken(token){ | |
| this.myInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`; | |
| } | |
| getCall(url) { | |
| return this.myInstance.get(url) | |
| } | |
| postCall(url, body) { | |
| return this.myInstance.post(url, body) | |
| .then(function (response) { | |
| console.log(response); | |
| }) | |
| .catch(function (error) { | |
| console.log(error); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment