我正在尝试设计端点,该端点将返回某些特定网页所需的数据。正常资源是例如Car。
{
"Manufacturer" : "Ford",
"Model" : "Focus",
"Colour" : "Nice Blue",
"ParkingPlace" : "House;1/floor;C/section;Blue/placenumber;42"
"note" : "I like the golden ratio. It has same sign as Passive House Institute in its logo.",
"anotherAttribute" : "Possibly large attribute ,which is not necessary to send to client in next described use case. Lets say, this field can be normally removed using hal and projections.",
"createdAt" : "2021-03-10T08:05:31.509+00:00",
"updatedAt" : "2021-03-10T08:05:31.509+00:00",
"_links" : {
"self" : {
"href" : "https://example.com:433/carapp/api/cars/9"
},
"car" : {
"href" : "https://example.com:433/carrapp/api/cars/9{?projection}",
"templated" : true
},
"makeObsolete" : {
"href" : "https://example.com:433/carapp/api/lifecycle/car/9/makeObsolete"
},
"customTags" : {
"href" : "https://example.com:433/carapp/api/testCases/9/customTags"
}
}
}
现在我有了屏幕,我必须在其中显示按单个选定参数分组的汽车。给定参数可以是“多级”(参见停车位属性)。所以我需要根据一些(用户选择的)属性在树视图中显示我的汽车实体。可选择的属性可以是“制造商”、“型号”、“颜色”和“停车位”。
我想设计(符合 HAL 原则”端点,它将向我发送单个用户操作所需的所有数据。例如,打开应用程序将请求按停车位分组的所有汽车。我希望端点将返回“文件夹”列表(“House 1”、“Underground Garage Harry”、“Some other park place”),和汽车实体列表,在“ParkingPlace”中没有设置任何内容。这些应该对事物进行分页(可以有很多不同的“文件夹”和汽车实体)。比,当用户想要扩展名为“House 1”的“文件夹”时,我希望端点能够返回给定的“文件夹”文件夹(即“A 楼”、“B 楼”和“C 楼”)以及汽车实体,其属性 ParkingPlace 等于“House;1”。
我希望所有“下载”的汽车实体都应该被缓存。例如,当用户确实将分组从 ParkingPlace 更改为 Model 时,web 将从 hal 后端请求“root”文件夹,它将返回“Focus”、“Fiesta”、“Galaxy”、“Mustang”等文件夹以及没有的汽车实体模型属性集。所有这些都应该分页。此外,当客户端(浏览器)上缓存了任何数据时,它们应该可以在不发送完整汽车实体的情况下使用。
这甚至可以在单个请求中完成吗(我假设后端服务器是无状态的,我没有看到太多机会在客户端缓存的东西的后端状态中存储)。在这种情况下,什么是“最佳实践”?