我正在设计一个RESTFUL API,我有一个家伙,我的一个操作:
客户端应用程序需要向服务器发出请求,以便向用户检索带有可用问题的JSON(基于某些限制)。
问题在于:
每个用户都属于一个客户端,这意味着客户端只会看到属于客户用户的问题。
先天,我不知道这些问题的身份。
用户可能需要其他用户已有的问题。
我想过使用:v1 / questions / next / {numberOfQuestions}
numberOfQuestions参数是可选的(默认为1),客户端将在服务器中获取。
哪种方法会更好?
谢谢!
答案 0 :(得分:1)
GET /v1/clients/{clientId}/users/{userId}/questions
返回:
{"questions":
[
{
"id": 1,
"title": "What is brown and barks?",
"answered": false
},
{
"id": 1,
"title": "What is brown and makes Moo?",
"answered": false
},
{
"id": 1,
"title": "What is brown and makes Meow?",
"answered": true
}
]
}
GET /v1/clients/{clientId}/users/{userId}/questions?answered=false
返回:
{"questions":
[
{
"id": 1,
"title": "What is brown and barks?",
"answered": false
},
{
"id": 1,
"title": "What is brown and makes Moo?",
"answered": false
}
]
}
GET /v1/clients/{clientId}/users/{userId}/questions?answered=false&limit=1
返回:
{"questions":
[
{
"id": 1,
"title": "What is brown and barks?",
"answered": false
}
]
}