[ ] client: create axios request for signin, signup to the server
[ ] server: send response from server to client
// short hand version is axios.post('./login', {theEmail: email, thePassword: password })
axios({
method: "post",
url: "/login",
data: {theEmail: email, thePassword: password}
}).then((response) => {
console.log(response);
}, (error) => {
console.log(error);
});
shorthand will be less stressful
// payload you sending via /user
const response = axios.post('/user', payload);
// response from server
const result = response.data
Server Side
Tips:
Use postman to run the endpiont to check if your endpoints run as expected
Get method - should do something and return detail when the client send this
Post method
get method example:
Example
app.get('/users', (req, res)=>{
// Do a default action when this is called, to do what, you decide
// return by res.send(thePayloadYouWantedToSend)
// It can send query by /users?variable1=info1&variable2=info2
const query = req.query.limit;
const variable1 = req.query.variable1;
const variable2 = req.query.variable2;
})
Example
app.get('/users/:id', (req, res)=>{
/*
* received from: req.params.id
* send payload to: res.send(datasendback)
*/
const id = req.params.id
res.send(dataSendBack)
});
post method example:
Example
app.post('/users', (req, res)=> {
// data from client is enbed into body, and it is an object
const user = req.body;
// data send back to client, let client know what happended
res.send(dataSendBack)
} )
Example
app.post('/users/:id', (req, res) =>{
const id = req.params.id
res.send(dataSendBack)
})
put method example
Example
app.put('/users/:id', (req, res)=> {
let user = req.body; // what is expected is to update user
const id = req.params.id
res.send(dataSendBack)
})
delete method example
app.delete('/user/:id', (req, res) => {
let id = req.params.id // expecting user id to be deleted, likely in the usertable
res.send(dataSendBack)
})
Objective
shorthand will be less stressful
Server Side
Tips: Use postman to run the endpiont to check if your endpoints run as expected
get method example:
post method example:
Example
put method example
delete method example
Knex