Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3663

Rest API response status code for different scenario's [closed]

$
0
0

I am developing few REST API in my Spring boot application so I have few clarifications regarding the Rest API Response HTTP status codes.

Below are the scenario's,

1) /products - returns List of Products

If there are no products in the database then what should be the status code -200 or 404

My answer is 200.

2) /products?page=0&size=10

If there are no products in the database then what should be the status code -200 or 404

My answer is 200

3) /products/{productId} - to product based on productId

If provided Pathvariable product id doesn't exist in the system then what would be the status code - 404 or 200.

My answer is 404.

4) /products - POST method - create a product

In the request body one of the field is invalid and throwing custom validation exception.

so my understanding need to throw either 400 or 422.

As I need to follow the API standards, need input here whether my answers are correct or any correction required for any scenario's.


Viewing all articles
Browse latest Browse all 3663

Trending Articles