4

This one may actually be 2 questions in one.

Studying some APIs I came across an api suggesting to have operand different from equal (=) inside the query string (http://www.salesboard.com/api/):

mycompany.salesboard.com/api/contacts?CompanyId!=5
or
mycompany.salesboard.com/api/contacts?Id<=5

Is that possible?? and by "possible" I mean: is that legal according to the standards? And if yes what are the possible problems to use such a url (compatibility, browser support, etc).

Now the second part of the question is: What is the best way to parse a URL such as this in PHP, has anyone ever used it?

PS: My question is not really problem but I thought it would be nice also for others to know.

Aslabs
  • 163
  • 1
  • 1
  • 4
  • I agree that a clean URL is much more "clean" but as @Bart said, the different operator url open a huge number of different possibilities. Making an API much more flexible. Anyway, the question was more theoretical, and less related to an API. – Aslabs Oct 16 '14 at 08:37

1 Answers1

5

The standard for URIs is STD 66, which currently maps to RFC 3986.

In section 3.4, it is defined what the query component may contain. (Note that it can’t contain an unencoded <).

However, it does not define any meanings for characters (like =) that can appear in the query component. Using a format like key=value is just a convention as far as the general URI standard is concernced.

Specific URI schemes might define such meanings, but the http URI scheme doesn’t seem to.

So semantically, there is no difference between using foo/bar, CompanyId!=5, or CompanyId-is-not-equal-to-5. They are just characters and it’s up to the consumers to interpret them.

unor
  • 1,102
  • 9
  • 19
  • Agreed. `=` only has semantic meaning insofar as it matches a key name to a value. – Robert Harvey Oct 16 '14 at 22:17
  • @unor: So what you are saying is that it's ok to do that. Right? What about the second part of the question: how can I interpret the sign in php? – Aslabs Oct 17 '14 at 08:22
  • @Aslabs: Yes, a query component like `CompanyId!=5` is valid in URIs. You can come up with any kind of string (as long as you percent-encode where necessary). // Unfortunately, I can’t say anything about parsing such a query component in PHP. (Maybe it might make sense to separate this second part about implementation into a separate question? No idea if it’s on-topic here or if it should be on [so].) – unor Oct 17 '14 at 14:25
  • @unor: I have marked the answer as final because in fact or Amat also the seconds part of the question. – Aslabs Oct 18 '14 at 18:05
  • just remember that ! is not a valid character in a url... you'd need to encode this as `?CompanyId%21=5` – N801 Apr 10 '21 at 03:39
  • @N801: `!` [doesn’t have to be](https://stackoverflow.com/a/38816380/1591669) percent-encoded in the query component – unor Apr 11 '21 at 10:21