I'm working on an API (along with an SPA) for a private project and I can't decide between two route naming conventions.
Suppose I have three tables in my database : Users
, Products
and Orders
. If I want users to be able to order products, which one of the following conventions should I follow?
POST /orders
with body{ "product": 1 }
POST /products/{id}/order
Note : In both case the user
would be inferred based on the access token provided.
To me, the main difference between the two solutions above resides in the type of interface to expose to the front-end developer : do I expose routes to resources (solution 1) or to actions to be performed (solution 2)?
Are there actual (dis)avantages to use one method over the other or is it just a matter of personal taste?
Correct me if I'm wrong, but from my understanding solution 1 is REST ("create this resource") while solution 2 isn't ("perform this action").
Also, with solution 1 each route would directly map to a table in my database and some people say it's a bad idea cause external developers can then infer the database's schema based on the API routes but honestly I don't see how it's a problem.