将多个查询参数传递给restful api的最佳方法是什么? [英] What is best way to pass multiple query parameters to a restful api?

查看:104
本文介绍了将多个查询参数传递给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,我将如何格式化一个返回所有带有 firstname==bob & 联系人的调用.姓==史密斯?

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?

我唯一的想法是:

http://api.myapi.com/contacts/firstname/bob&姓=史密斯

但这似乎不对;-(

请指教.

此外,是否有任何 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.

这篇关于将多个查询参数传递给restful api的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆