3

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.

  • 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 8:37
3

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.

  • 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 8: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 Stack Overflow.) – 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.