1

I was under the impression that REST was supposed to use routing, like this:

http://server/api/accounts/2

Rather than something like this:

http://server/api/accounts?id=2

I've seen lots of examples using the query string, but I would've expected people to be saying that's wrong. However, that doesn't seem to be the case.

For an [HTTPGET], should I prefer one over the other?

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
birdus
  • 7,062
  • 17
  • 59
  • 89

1 Answers1

1

Path parameter is used to identify a specific resource or resources.
Query parameter is used to sort/filter those resources.

It is a good practice to make all required parameters as path parameters, and all optional as query parameters.

In your case, if your :id parameter uniquely identifies an account, this should be a path parameter, i.e.: /api/accounts/:id

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125