Skip to content

Commit

Permalink
writing axios requests
Browse files Browse the repository at this point in the history
  • Loading branch information
aatmanvaidya committed Sep 11, 2023
1 parent 8d001ff commit 4d5010a
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion browser-extension/plugin/src/ui-components/pages/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,51 @@ async function resetAccount(accessToken) {
);
}

//https://www.freecodecamp.org/news/axios-react-how-to-make-get-post-and-delete-api-requests/
// const axiosInstance = axios.create({
// baseURL: API_URL,
// });

// GET request for slur and category
async function getSlurAndCategory(accessToken) {
const result = await axios.get(`${API_URL}/slur`, {
headers: {
Authorization: `token ${accessToken}`
}
});
console.log('GET slur and category data', result.data);
return result.data;
}

// POST request for slur and category
async function createSlurAndCategory(accessToken, slurData) {
return axios.post(`${API_URL}/slur/create`, slurData, {
headers: {
Authorization: `token ${accessToken}`,
'Content-Type': 'multipart/form-data'
}
});
}

// PUT request for slur and category
async function updateSlurAndCategory(accessToken, slurId, updatedData) {
return axios.put(`${API_URL}/slur/${slurId}`, updatedData, {
headers: {
Authorization: `token ${accessToken}`,
'Content-Type': 'multipart/form-data'
}
});
}

// DELETE request for slur and category
async function deleteSlurAndCategory(accessToken, slurId) {
return axios.delete(`${API_URL}/slur/${slurId}`, {
headers: {
Authorization: `token ${accessToken}`
}
});
}

export default {
login,
getPreferenceForUser,
Expand All @@ -107,5 +152,9 @@ export default {
invokeNetwork,
registerNewUser,
getArchive,
resetAccount
resetAccount,
getSlurAndCategory,
createSlurAndCategory,
updateSlurAndCategory,
deleteSlurAndCategory
};

0 comments on commit 4d5010a

Please sign in to comment.