创建RESTful API时,应该在相同的URL上使用HTTP动词(如果可能),还是在每个操作中创建特定的URL?
例如:
GET /items # Read all items
GET /items/:id # Read one item
POST /items # Create a new item
PUT /items/:id # Update one item
DELETE /items/:id # Delete one item
或使用特定的网址,例如:
GET /items # Read all items
GET /item/:id # Read one item
POST /items/new # Create a new item
PUT /item/edit/:id # Update one item
DELETE /item/delete/:id # Delete one item
PUT
andDELETE
,我宁愿将其添加到路径中,而不要使用查询字符串来区分它。这不是对现有操作的查询字符串修改;这是一个单独的操作。