What is the difference between passing query params as /cars/id/toyota
vs /cars?id=toyota
in a webservice?
Is one REST vs other web service type?
Passing parameter in Rest service in the form of Url or query string, both have different significance. In simple words
/cars/id/toyota
in this toyta is variable and your service expecting something after id/{variablename}
otherwise it gives an error (endpoint not found). So in this case your variable became mandatory.
/cars?id=toyota
in this case your query string (Id) becomes optional.
So use query string whenever you want to make that variable optional. :)
Nothing, obviously–it all depends on how the consuming service expects to retrieve parameters.
It depends on the receiving party (your web server and the framework you use on that web-service). Both or neither could conceivably be REST web-services, depending on your implementation.
Conceptually, the difference lies in the path from the web-server root (/
) and parameters:
/cars/id/toyota
is a URL to path /cars/id/toyota
without parameters
/cars?id=toyota
is a URL to path /cars
with parameter named id
with value toyota