什么是传递多个查询参数一个宁静的API的最佳方式? [英] What is best way to pass multiple query parameters to a restful api?
问题描述
我设计的RESTful API和想在设计,通常是主叫要基于多个搜索参数来查询记录的API一些建议。
I am designing RESTful Api's and would like some advice on designing an API where the caller wants to query records based on more than one search parameter.
我只看到了使用一个参数RESTful API中。
I have only seen restful apis that use one parameter.
我应该怎么做呢?
例如。如果我已经创建了一个联系人列表宁静的API,我将如何格式化返回与名字的所有联系人通话==鲍勃和放大器;姓史密斯==?
e.g. if i have created a restful api for a list of contacts, how would I format a call that returned all contacts with firstname==bob & surname==smith?
我想这应该是一个GET,因为我取回?
I guess it should be a GET because I am retrieving?
我唯一的想法是:
<一个href=\"http://api.myapi.com/contacts/firstname/bob&surname=smith\">http://api.myapi.com/contacts/firstname/bob&surname=smith
但是,这看起来不正确; - (
But that doesn't seem right ;-(
请咨询。
另外,做任何的PHP框架的支持呢?例如symfony中,konstrukt等。
Also, do any of the php frameworks support this? e.g. symfony, konstrukt etc.
推荐答案
我觉得
http://api.myapi.com/contacts?firstname=bob&surname=smith
是,如果你有一组参数的路要走,所有这些都是可选的。
is the way to go if you have a set of parameters, all of which are optional.
这篇关于什么是传递多个查询参数一个宁静的API的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!