Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct REST URI Syntax

Tags:

rest

I've seen some people say that this is the only way to do REST:

/car

Displays all cars

/car/123

Displays information about the car with ID of 123

I have also seen others that prefer to do this with REST:

/car

Displays all cars

/car?id=123

Displays information about the car with ID of 123

Which is correct for REST?

Please note that I am only posting this question to get a real answer, I am not trolling. If REST is not defined enough for a definitive answer, or it is not clear which option above is "correct" for REST, then that would be a fine answer for me. I am simply trying to understand REST.

Thank you.

like image 290
flying227 Avatar asked Feb 28 '26 20:02

flying227


1 Answers

REST was originally designed based on a purely path-driven architecture, although different implementations of REST APIs in software like Flickr and JIRA have clouded this a bit. In the end what is most important is that the standards used within the entirety of your own API are consistent (i.e. don't use /api/user/21 for getting a user and then /api/group?id=3 for another). Ideally, use paths to locate a resource and then use different HTTP verbs to determine what you're doing with that resource (GETing it, POSTing a new one, PUTting an update, etc).

Wikipedia has a very informative article on it.. http://en.wikipedia.org/wiki/Representational_state_transfer

like image 139
jbeale Avatar answered Mar 02 '26 13:03

jbeale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!