José María
José María

Reputation: 809

Can I prefix with $ (dollar sign) my URL query string parameters safely?

I am starting to implement filtering through query strings in my API REST application where I can perform filtering on any field passed to a entity in my database. But there are especial parameters that I want to differentiate like; sort, page, direction, etc from the rest of fields that will be used to filter the collection.

I want to avoid using an implementation like:

/?filters=field1:value1,field2:value2&page=3&per_page=50

Because I will need to make a custom parser to the filters value.

My desired structure is something more plain, like this:

/?lastname=Halden&country=somewhere&$sort=lastname

So, all the properties that aren't prefixed with $ are used to make the filter and the other properties with the prefix are used to tweak the result.

My actual question is that if it is safe?. If there can exist a problem in the moment to parse the whole query string in some libraries.

Upvotes: 2

Views: 4152

Answers (1)

Amin J
Amin J

Reputation: 1209

It should be ok. As a matter of fact, ODATA, one of the widely used REST standards in enterprise software uses $ the same way you want to use. Another sensible option you could use is _ (e.g. _sort, _page, etc.)

Upvotes: 4

Related Questions