-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExampleApi.js
36 lines (33 loc) · 1.31 KB
/
ExampleApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// note: if axios install it by npm install axios
const axios = require('axios')
const baseUrl = "http://127.0.0.1:5000/";
const todos = baseUrl + "todos";
export default {
endpointLoadWithFetch() {
return {
getOne: ({ id }) => fetch(todos + `/${id}`), //id_url
getAll: () => fetch(todos), //url
create: (data) => fetch(todos, data), //url, data
update: ({ id }, data) => fetch(todos + `/${id}`, data), //url, data
delete: ({ id }) => fetch(todos + `${id}`)
}
},
endpointLoadWithAxios() {
return {
getOne: ({id}) => axios.get(todos + `/${id}`), //id_url
getAll: () => axios.get(todos),
create: (data) => axios.post(todos, data), //url, data
update: ({ id }, data) => axios.put(todos + `/${id}`, data), //url, data
delete: ({ id }) => axios.delete(todos + `/${id}`)//id_url
}
}
}
// componentDidMount(){
// endpointLoadWithAxios().getAll()
// .then(response => response.json() //fetch method need to convert json
// .then(data => this.setState({ todos: data }))); //define converted data state variable
//}
// componentDidMount(){
// endpointLoadWithAxios().getAll()
// .then(response => this.setState({ axiosTodos: response.data }))
//}