Suppose I have a products API:
/products
GET: List of products
POST: Creates a product
/products/12345
GET: Get a specific product
PUT: Updates a specific product
So is this a good idea for the response:
{
message: // Containing the list of products
}
If I encounter an error, I would just put it in the message.
Or would this be better practice:
If correct response:
{
products: // Containing the list of products
}
else:
{
error: // Containing the error
}
The status code would be sent along with the response. So in the client, I could modify how it reads the response based on if the response is ok.