I am attempting to send an object named Pack to my API Rest server using my Angular service. Below is the function I have set up for this task:
save_pack(Pack: any){
return new Promise((resolve, reject) =>{
this.http
.post("http://localhost:8000/save_pack",Pack)
.subscribe(res => {
resolve(res);
},
(err: any) => {
reject(err);
}
)
});
}
}
However, I realize that the way I am currently sending Pack is incorrect. I would like to understand how to properly send Pack so that I can receive it in my API Rest and then access that received object. When using GET, I know you can do the following:
const Pack = req.query.Pack;
How can I achieve the same result with POST?
The POST function in my API Rest is as follows:
app.post('/save_pack', async (req,res) => {
console.log(req.body)
const Pack = req.body.Pack;
console.log("Package: " + Pack);
let result = await save_pack(Pack);
res.send(result)
return res;
})