I have a question regarding the DELETE endpoint in my REST API.(我对REST API中的DELETE端点有疑问。)
To give a bit of context, in my frontend I have a 'clients' table with serverside pagination, so whenever I change page I send a request to the server which returns an object like the following:(为了说明背景,在我的前端,我有一个带有服务器端分页的“客户”表,因此,每当我更改页面时,我都会向服务器发送一个请求,该请求返回如下对象:)
{
"items": [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}, {id: 3, name: 'buzz'}],
"itemCount": 3,
"totalItems": 56,
"pageCount": 19,
"next": "http://localhost:3000/api/clients?page=2&limit=3",
"previous": "",
"currentPage": 1
}
When I delete or modify a client, I would like to return an updated version of the clients list, but I'm not sure whats the best way to do this without sending information on the page and limit per page .(当我删除或修改客户端时,我想返回客户端列??表的更新版本,但是我不确定在不发送页面信息和每页 限制的情况下实现此目的的最佳方法是什么。)
The solutions I thought of to solve this issue are:(我想到的解决方案是:)
I could send the information of the page and limit per page with the requests and retrieve the information in my delete endpoint after deleting the client.(删除客户端后,我可以发送页面信息并限制每个页面的请求,并在我的删除端点中检索信息。)
However, this seems very inefficient because I would be adding this extra info to endpoints not only for clients but for other models as well, as I have the same issue with products for example.(但是,这似乎效率很低,因为我会将这些额外的信息不仅添加到客户端,还添加到其他模型的端点,例如,我在产品方面也遇到了同样的问题。)I could send a delete request on my frontend and when that finishes make a request to get the updated information separately (maybe even in parallel?).(我可以在前端发送删除请求,完成后再发出请求以分别获取更新的信息(甚至可以并行获取)。)
But this seems inefficient as well due to the extra network request.(但是由于额外的网络请求,这似乎效率也很低。)
What would be the best way to go about this problem?(解决此问题的最佳方法是什么?)
ask by Showner91 translate from so