1

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?

4

3 回答 3

1

Passing parameter in Rest service in the form of Url or query string, both have different significance. In simple words

  1. /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.

  2. /cars?id=toyota in this case your query string (Id) becomes optional. So use query string whenever you want to make that variable optional. :)

于 2013-02-27T21:46:50.057 回答
0

Nothing, obviously–it all depends on how the consuming service expects to retrieve parameters.

于 2013-02-26T22:58:21.850 回答
0

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

于 2013-02-26T23:01:27.690 回答