This is my Angular service method that returns the error:
export class CartItemService {
constructor(private http:HttpClient) { }
addCartItem(pId:string, uId:string) {
return this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`);
}
}
And here is the component method that calls the service method:
addCartItem(pId:string, uId:string) {
this.cartItemService.addCartItem(pId,uId).subscribe({
next:(res) => alert('cart item added'),
error: (err) => alert('fail to add to cart')
})
}
What am I missing in the service method? I really have nothing else to pass in. All I want to do is to pass in two parameters to the backend and let Spring Boot do the rest of the POST.
CodePudding user response:
You have to provide a body for your post request, though that body may be empty. So you could do this for example:
this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`, {})