I am working on a one page web application for an online shop in Angular which will rely on a REST API handled by Symfony. One of the first request I make is that I need to know if the customer has an active cart or not. So I have a route /get-user-cart which returns null if the user has no cart (then I display a button to create a cart), if the user has an active cart I return the cart and its content.
My question is what HTTP code should I return if the user has no cart? Should I return a 200 code (the server answered correctly and the response is null) or a 404 content not found code?
Advertisement
Answer
Ideally you should return 200 status code with null response. Since cart is not a resource, Where as each of the contents inside carts can be considered as resource.