axios added

This commit is contained in:
Olu Amey
2023-01-26 16:21:11 -05:00
parent 20ff5e65ce
commit 92e8cabaed
3 changed files with 176 additions and 1 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
{
"name": "nft-max-react",
"name": "myFit-App",
"version": "0.1.0",
"private": true,
"dependencies": {
@@ -8,6 +8,7 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.24.0",
"chart.js": "^3.7.1",
"chartjs": "^0.3.24",
"faker": "^6.6.6",
+83
View File
@@ -0,0 +1,83 @@
import React from "react";
import Axios from "axios";
class SiteService {
constructor() {
console.log("Er are here anyway");
}
// Blog Data {Get}
blogData() {
return this.getAuxEnd("/blogdata", null);
}
// Country Data {GET}
countryData() {
return this.getAuxEnd("/country", null);
}
// Contact Data{POST}
contactData() {
return this.postAuxEnd("/contact", null)
}
faqData() {
return this.getAuxEnd("/faq", null);
}
priceData() {
return this.getAuxEnd("/pricing", null);
}
//---------------------------------------- -----
//---------------------------------------- -----
// Unified call below
//---------------------------------------- -----
//---------------------------------------- -----
getAuxEnd(uri, reqData) {
const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri;
return Axios.get(endPoint)
.then((response) => {
// console.log(response);
// res = response;
// console.log("~~~~~~~ Toks2 GET ~~~~~~~~");
return response;
})
.catch((error) => {
if (error.response) {
//response status is an error code
console.log(error.response.status);
} else if (error.request) {
//response not received though the request was sent
console.log(error.request);
} else {
//an error occurred when setting up the request
console.log(error.message);
}
});
}
postAuxEnd(uri, reqData) {
const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri;
return Axios.post(endPoint, reqData)
.then((response) => {
console.log(response);
// res = response;
console.log("~~~~~~~ Toks2 POST ~~~~~~~~");
return response;
})
.catch((error) => {
if (error.response) {
//response status is an error code
console.log(error.response.status);
} else if (error.request) {
//response not received though the request was sent
console.log(error.request);
} else {
//an error occurred when setting up the request
console.log(error.message);
}
});
}
}
export default SiteService;
+91
View File
@@ -0,0 +1,91 @@
import React from "react";
import Axios from "axios";
class usersService {
constructor() {
console.log("Er are here anyway");
}
logInUser(reqData) {
debugger;
/*
clean up the request data here
*/
return this.postAuxEnd("/login", reqData);
}
//---------------------------------------- -----
//---------------------------------------- -----
// Unified call below
//---------------------------------------- -----
//---------------------------------------- -----
getAuxEnd(uri, reqData) {
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
return Axios.get(endPoint)
.then((response) => {
// console.log(response);
// res = response;
// console.log("~~~~~~~ Toks2 GET ~~~~~~~~");
return response;
})
.catch((error) => {
if (error.response) {
//response status is an error code
console.log(error.response.status);
} else if (error.request) {
//response not received though the request was sent
console.log(error.request);
} else {
//an error occurred when setting up the request
console.log(error.message);
}
});
}
postAuxEnd(uri, reqData) {
const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri;
const token = '..your token..'
let axiosConfig = {
headers: {
'Accept': 'application/json',
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json;charset=UTF-8',
'Authorization': `Basic ${token}`,
}
};
//Access-Control-Allow-Origin
var postData = {
email: "test@test.com",
password: "password"
};
Axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8';
Axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*';
return Axios.post(endPoint, postData,axiosConfig)
.then((response) => {
console.log(response);
// res = response;
console.log("~~~~~~~ Toks2 POST ~~~~~~~~");
return response;
})
.catch((error) => {
if (error.response) {
//response status is an error code
console.log("ERROR-------------------------------------------------------");
console.log(error.response.status);
console.log("ERROR-------------------------------------------------------");
} else if (error.request) {
//response not received though the request was sent
console.log("ERROR2-------------------------------------------------------");
console.log(error.request);
console.log("ERROR2-------------------------------------------------------");
} else {
//an error occurred when setting up the request
console.log("ERROR3-------------------------------------------------------");
console.log(error.message);
console.log("ERROR3-------------------------------------------------------");
}
});
}
}
export default usersService;