-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fe] chore: Refactor api calls out of app component
- Loading branch information
1 parent
fbcac54
commit 137cceb
Showing
3 changed files
with
60 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import axios from 'axios'; | ||
|
||
import type NoteType from "../types/note"; | ||
|
||
const URL = | ||
process.env.REACT_APP_API_BASE_URL || "http://localhost:5000/api/notes"; | ||
|
||
|
||
export const postNote = async (newNote: NoteType) => { | ||
const response = await axios.post( | ||
URL, | ||
{ | ||
title: newNote.title, | ||
content: newNote.content, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
return response; | ||
}; | ||
|
||
|
||
export const patchNote = async (updatedNote: NoteType) => { | ||
const response = await axios.put( | ||
`${URL}/${updatedNote.id}`, | ||
{ | ||
title: updatedNote.title, | ||
content: updatedNote.content, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
return response; | ||
}; | ||
|
||
export const removeNote = async (id: number) => { | ||
const response = await axios.delete(`${URL}/${id}`); | ||
return response; | ||
} | ||
|
||
export const getNotes = async () => { | ||
const response = await axios.get(URL); | ||
return response; | ||
} |
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