Pros/cons of passing a record ID through the URL vs. a parameter

266 views Asked by At

I'm working on an API and am wondering if there are any advantages/disadvantages of accessing a record by passing the ID through the URL vs. as a parameter.

Example: Getting info of a message of ID 1

You could do this with example.com/messages/1 which would return the message of ID 1 in JSON format.

Or you could do example.com/messages?id=1.

Are there any reasons to choose one over the other or would it just be personal preferences?

1

There are 1 answers

0
Eric Stein On

Your former example is a little more human-readable and intuitive. It will be easier for developers to work with on both sides of the API. It's also much more standard for web APIs. Most frameworks are designed to support URLs in both forms. All other things being equal, the first example is probably a better bet.