-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved API calls from actions to apis module.
- Loading branch information
1 parent
12f6dd7
commit caec7c4
Showing
6 changed files
with
76 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,73 @@ | ||
import axios from 'axios'; | ||
import CONSTANTS from '../constants'; | ||
|
||
const instances = {}; | ||
const {endpoints} = CONSTANTS; | ||
|
||
export const createAxiosInstances = (endpoints) => { | ||
Object.keys(endpoints).forEach((entry) => { | ||
instances[entry] = axios.create({ | ||
baseURL: endpoints[entry], | ||
timeout: 30000 | ||
}); | ||
const axiosClient = axios.create({ | ||
baseURL: endpoints.electron, | ||
timeout: 30000 | ||
}); | ||
|
||
/** | ||
* Generic HTTP request function to wrap axios operations | ||
* @param url | ||
* @param method | ||
* @param payload | ||
* @param client | ||
* @returns {Promise<void>} | ||
*/ | ||
const executeRequest = async ({url, method = 'get', payload = null, client = axiosClient}) => { | ||
const {data} = await client.request({ | ||
url, | ||
method, | ||
data: payload | ||
}); | ||
|
||
return data; | ||
}; | ||
|
||
/** | ||
* Execute GET request against the /configure endpoint | ||
* @returns {Promise<*>} | ||
*/ | ||
export const getConfigure = async () => { | ||
return await executeRequest({url: 'configure'}); | ||
}; | ||
|
||
/** | ||
* Execute POST request against the /configure endpoint with payload | ||
* @param {Object} payload | ||
* @returns {Promise<*>} | ||
*/ | ||
export const postConfigure = async (payload) => { | ||
return await executeRequest({url: 'configure', method: 'post', payload}); | ||
}; | ||
|
||
export default instances; | ||
/** | ||
* Execute GET request against the SPA /refresh endpoint | ||
* @returns {Promise<*>} | ||
*/ | ||
export const getRefresh = async () => { | ||
// Note: this call triggers the /refresh route on the SPA to make sure that | ||
// we get routed to the right component. | ||
return await executeRequest({url: 'refresh', client: axios}); | ||
}; | ||
|
||
/** | ||
* Execute GET request against the SPA /logout endpoint | ||
* @returns {Promise<*>} | ||
*/ | ||
export const getLogout = async () => { | ||
// Note: this call triggers the /logout route on the SPA to make sure that | ||
// we get routed to the right component. | ||
return await executeRequest({url: 'logout', client: axios}); | ||
}; | ||
|
||
/** | ||
* Execute DELETE request against the /profile endpoint with payload | ||
* @param {Object} payload | ||
* @returns {Promise<*>} | ||
*/ | ||
export const deleteProfile = async (payload) => { | ||
return await executeRequest({url: 'profile', method: 'delete', payload}); | ||
}; |
This file contains 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