最佳答案
我正在构建一个库存管理系统,我正忙于设计(思考) API 和 REST 实现。
我有以下资源,在这些资源上你可以执行许多操作。 每个操作都会修改资源,在某些情况下还会创建新资源,并创建历史记录或事务。
我正在寻找一些关于 URL 和资源设计的可用性和可接受性方面的专家意见。陷阱和现实世界的例子,任何意见或批评欢迎。
我担心的是,整个应用程序可能是围绕这一大型资源开发的? 我的后端堆栈将是 C # 和服务堆栈框架,对于前端,我将使用 HTML 和 AngularJS。不过也没什么区别。
场景1。 典型操作包括:
POST /inventory/{id}/move
POST /inventory/{id}/scrap
PUT /inventory/{id}/takeon
POST /inventory/{id}/pick
PUT /inventory/{id}/receive
POST /inventory/{id}/hold
POST /inventory/{id}/release
POST /inventory/{id}/transfer
POST /inventory/{id}/return
POST /inventory/{id}/adjustment
{
"userID": "", //who is doing the actions (all)
"tolocationID": "", //new location for inventory (move/takeon/pick/receive/transfer/return)
"qty": "", //qty (pick/receive/takeon/transfer/return)
"comment": "", //optional for transaction (all)
"serial": "", //(takeon/receive)
"batch": "", //(takeon/receive)
"expirydate": "", //(takeon/receive)
"itemCode": "", //(takeon/receive)
"documentID": "", //(pick/receive/return/transfer)
"reference" :"", //(all)
"UOM" :"", //(all)
"reference" :"", //(all)
}
就标准而言,这是可以接受的吗。 另一种方法可能是。
场景2。
POST /inventory/{id}/move
POST /inventory/{id}/scrap
PUT /inventory/{id}/takeon
POST /document/{id}/pick //**document**
PUT /document/{id}/receive //**document**
POST /inventory/{id}/hold
POST /inventory/{id}/release
POST /document/{id}/transfer //**document**
POST /document/{id}/return //**document**
POST /inventory/{id}/adjustment
然后改变资源。
第三种情况,我认为是错误的
POST /transaction/move/{...}
POST /transaction/scrap/{...}
PUT /transaction/takeon/{...}
POST /transaction/pick/{...}
PUT /transaction/receive/{...}
POST /transaction/hold/{...}
POST /transaction/release/{...}
POST /transaction/transfer/{...}
POST /transaction/return/{...}
POST /transaction/adjustment/{...}
欢迎任何意见,不寻求答案,但更多的意见设计考虑?
感谢您花时间阅读这篇文章!