Sample React-Express-MongoDB (#59)
Signed-off-by: Afzal <sah.afzal@gmail.com>
This commit is contained in:
22
react-express-mongodb/frontend/src/utilities/httpRequestHandler.js
vendored
Normal file
22
react-express-mongodb/frontend/src/utilities/httpRequestHandler.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import axios from 'axios';
|
||||
import config from '../config/constants';
|
||||
|
||||
|
||||
export async function request (method, uri, data, headers = null, params = null) {
|
||||
let url = (config.API_BASE_URL + uri);
|
||||
let query = {
|
||||
method: method,
|
||||
url: url
|
||||
};
|
||||
if (headers !== null)
|
||||
query.headers = headers;
|
||||
if (params !== null)
|
||||
query.params = params;
|
||||
if (method === 'post' || method === 'put' || method === 'delete' || method === 'patch')
|
||||
query.data = data;
|
||||
try {
|
||||
return await axios(query);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user