此用例的 REST API 模式

REST API pattern for this usecase

我需要通过 AJAX 调用来实现这一点,其中一个方便的辅助函数(在服务器上)可以解决问题,但 REST 方法是什么?

我在浏览器端有一个项目(猫)列表,我需要为所有这些项目填充另一个详细信息。

input = [list of cat ids]
output = [list of {}s which has cat ids & age]

如果我不需要关心适当的 REST API,我会声明一个方法 populate_cat_details() 并通过 GET http://example.com?method=populate_cat_details&cat_ids=1,2,3,4 调用它 returns一个 JSON

GET http://www.example.com/cats    -> return all cats
GET http://www.example.com/cats/:id    -> return 1 cat by id
GET http://www.example.com/cats?id=x&id=y&id=z -> return n cats matching ids
GET http://www.example.com/cats?age=2&age=3&age=4  -> return n cats matching ages 
GET http://www.example.com/cats?id=x&id=y&id=z&age=2&age=3&age=4  -> return n cats matching ids and ages

如果传递参数如 coma-separated 值 ex: ids=1,2,3

你有其他方法

看这里: http://www.restapitutorial.com/lessons/restfulresourcenaming.html