CodePark/ questions / REST resource design
START PRACTICINGPRACTICE
Backend question · HTTP & API design › REST resource design

Which endpoint follows REST conventions for fetching one product?

GET /products/12

GET /products/12 is correct. In REST, the URL names a resource with a plural noun and an ID. The HTTP method says the action.

Why the others are wrong:

•
GET /getProduct?id=12 and GET /product/fetch/12 put verbs like get or fetch in the path. This repeats what the method already says.
•
POST /products/get/12 uses POST for a read. POST is not safe (it may change data) and is not cached, so you lose both benefits of GET.