5

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.

1
  • 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. Commented Oct 16, 2014 at 8:37

1 Answer 1

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.

6
  • Agreed. = only has semantic meaning insofar as it matches a key name to a value. Commented Oct 16, 2014 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? Commented Oct 17, 2014 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.) Commented Oct 17, 2014 at 14:25
  • @unor: I have marked the answer as final because in fact or Amat also the seconds part of the question. Commented Oct 18, 2014 at 18:05
  • just remember that ! is not a valid character in a url... you'd need to encode this as ?CompanyId%21=5 Commented Apr 10, 2021 at 3:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.