Prashant Shilimkar
Prashant Shilimkar

Reputation: 8820

REST url param naming convention

I have a REST call to search students

/students?name=&no=

name and no are optional.

I am searching students with name contains. i.e. if I send name="sh" then it will return all students which name contains "sh".

AND

for no, it is no starts with ie if no=10 then it will return all students with no starts with 10

What are standard naming convention for such parameters. Can I say

/students?nameContains=&noStartsWith=

OR

/students?name=&no=

Which one is correct way ?

Upvotes: 2

Views: 2594

Answers (1)

Eric Stein
Eric Stein

Reputation: 13672

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. But if you're going to need nameContains, nameStartsWith, nameEndsWith, etc., that's going to get messy fast. Then you should consider either a separate resource that specifies search criteria or adding wildcards to your name, such as:

?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.

Upvotes: 2

Related Questions