Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I pass multiple parameters to an ASP.Net Web API GET?
    primarykey
    data
    text
    <p>I am using the .Net MVC4 Web API to (hopefully) implement a RESTful api. I need to pass in a few parameters to the system and have it perform some action, then return a list of objects as the results. Specifically I am passing in two dates and returning records that fall between them. I'm also keeping track of the records returned so that subsequent calls do not get reprocessed in the system.</p> <p>I've considered a few approaches:</p> <ol> <li><p>Serializing the params into one single JSON string and picking it apart in the API. <a href="http://forums.asp.net/t/1807316.aspx/1" rel="noreferrer">http://forums.asp.net/t/1807316.aspx/1</a></p></li> <li><p>Pass the params in the query string.<br> <a href="https://stackoverflow.com/questions/2640560/what-is-best-way-to-pass-multiple-query-parameters-to-a-restful-api">What is best way to pass multiple query parameters to a restful api?</a></p></li> <li><p>Defining the params in the route: api/controller/date1/date2</p></li> <li><p>Using a POST that inherently lets me pass an object with params.</p></li> <li><p>Researching ODATA since the Web API (currently) supports it. I haven't done much with this yet so I'm not very familiar with it.</p></li> </ol> <p>It seems that proper REST practices indicate when data is pulled, you should use a GET. However, GET should also be nullipotent (produces no side-effects), and I wonder if my specific implementation violates that since I mark records in the API system, hence I am producing side-effects.</p> <p>It also led me to the question of supporting variable parameters. If the input parameter list changes, it would be tedious to have to re-define your route for Choice 3 if that happens a lot. And what might happen if the parameters are defined at run-time...</p> <p>In any case, for my specific implementation, which choice (if any) seems best?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload