Question

I'm developing a web client for a RESTful API. Suppose two types of APIs (for the same task) have been exposed.

  1. Parameters as part of the URL-path (i.e. /api/resource/parametervalue )
  2. Parameters as a query argument (i.e. /api/resource?parameter=value )

From the web client perspective, can you suggest me what is better of the two and why.

Was it helpful?

Solution

Option 2 is the way to go. If your parameters aren't resources, there's no reason for them to be endpoints. It's just going to clutter up your API. And what if you have two or three or ten parameters? Is the client supposed to remember the exact order they go in? What if they only want to specify parameters 2, 3, and 7? Do you really want to have to write the back end that figures out exactly what the call should be?

OTHER TIPS

I believe that it is better to use the second option - as query argument. My opinion is based on:

  1. This is standart form of HTTP, which is used for work with GET requests.
  2. Key\value style easy to parse.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top