[英]REST url param naming convention
I have a REST call to search students 我有一个REST电话来搜索学生
/students?name=&no=
/生?名称=无=
name and no are optional. 名称和否是可选的。
I am searching students with name contains. 我正在搜索包含名称的学生。 ie if I send name="sh" then it will return all students which name contains "sh".
即,如果我发送name =“ sh”,它将返回名称包含 “ sh”的所有学生。
AND 和
for no, it is no starts with ie if no=10 then it will return all students with no starts with 10 不,它不是以“ s”开头的,即如果“ no = 10”,它将返回所有没有以“ 10” 开头的学生
What are standard naming convention for such parameters. 这些参数的标准命名约定是什么。 Can I say
我能说......么
/students?nameContains=&noStartsWith=
/生?nameContains = noStartsWith =
OR 要么
/students?name=&no=
/生?名称=无=
Which one is correct way ? 哪一种是正确的方法?
There exist no standard naming conventions for query parameters. 对于查询参数,没有标准的命名约定。 In your specific case, it depends on the likelihood of future requirements.
在您的特定情况下,这取决于将来需求的可能性。 If it's just
nameContains
, well, that's much better than name
. 如果只是
nameContains
,那比name
更好。 But if you're going to need nameContains
, nameStartsWith
, nameEndsWith
, etc., that's going to get messy fast. 但是,如果你要需要
nameContains
, nameStartsWith
, nameEndsWith
等,那将变得混乱很快。 Then you should consider either a separate resource that specifies search criteria or adding wildcards to your name
, such as: 然后,您应该考虑使用指定搜索条件的单独资源或在
name
添加通配符,例如:
?name=Bob* <!-- name starts with Bob -->
?name=*h <!-- name ends with h -->
?name=Sa? <!-- name has three letters and starts 'Sa' -->
For truly complex cases, you need to think about either supporting regexes or using an existing library to handle search. 对于真正复杂的情况,您需要考虑支持正则表达式或使用现有库来处理搜索。 Also think about if you need to support
?nameIgnoreCase
, which would argue strongly in favor of wildcards rather than multiple query parameters. 还考虑一下是否需要支持
?nameIgnoreCase
,这将强烈支持通配符而不是多个查询参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.