Method Url: /todos
HTTP method: [GET]
If you successfully fetch all todos the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
[
{
id: 1,
todo: "Walk the dog"
}
]
Method Url: /todos/:id
HTTP method: [GET]
example call:
axios.get('http://localhost:5000/todos/1')
.then((res) => {
this.setState({
todo: res.data.todo
})
})
.catch(err => {
console.log(err)
})
If you successfully fetch a todo the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
id: 1,
todo: "Walk the dog"
}
Method Url: /todos
HTTP method: [POST]
example call:
axios.post('http://localhost:5000/todos/')
.then((res) => {
this.setState({
todos: [...this.state.todos, res.data.todo]
})
})
.catch(err => {
console.log(err)
})
If you successfully created a todo the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
id: 1,
todo: "New todo"
}
Method Url: /todos
HTTP method: [PUT]
example call:
axios.put('http://localhost:5000/todos/', { id: 1, todo: "Updated todo" })
.then((res) => {
this.setState({
todo: res.data.todo
})
})
.catch(err => {
console.log(err)
})
If you successfully update a todo the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
id: 1,
todo: "Updated todo"
}
Method Url: /todos/:id
HTTP method: [DELETE]
example call:
axios.delete('http://localhost:5000/todos/1')
.then((res) => {
this.setState({
message: res.data.message
})
})
.catch(err => {
console.log(err)
})
If you successfully delete a todo the endpoint will return an HTTP response with a status code
200
and a body as below.
example:
{
message: "Todo successfully deleted"
id: 1
}