爲了開發一個REST Web服務有5個基本用例(在我看來)REST架構DTO的
/api/entities - GET
/api/entities/{id} - GET
/api/entities - POST
/api/entities/{id} - PUT
/api/entities/{id} - DELETE
一個DTO提供所需數據的最佳表徵與Web服務交互。
我喜歡這兩個概念,但我在哪裏掙扎是如何組織DTO的關於他們如何與特定的Web服務交互。
每個Web服務應該只有一個DTO嗎?例如:
EntityDto
- Property1
- Property2
- Property3
- Property4
- Property5
或者應該有每個用例的DTO?例如:
GetEntityDto
- Property1
- Property2
- Property3
- Property4
- Property5
AddEntityDto
- Property2
- Property3
- Property4
- Property5
EditEntityDto
- Property4
- Property5
我看到它的方式,如果只能更新2個屬性,爲什麼要發送所有5個?
處理DTO與REST Web服務有關的最佳方法是什麼?
我給了你一個話題,但是別忘了還有其他的方法,比如'PATCH',它是用於部分修改的。 – thecoshman