title: Multiple optional query string parameters REST API GET
body: <p>I am using web api 2 to implement a restful service. After doing some research on best practices everyone seems like they are having different opinions on how to do the following. I have a GET </p>
  
  <pre><code>public HttpResponseMessage Get(string crewId, string shiftDate, int offset = 1, int limit = 10)
  </code></pre>
  
  <p>This GET method returns a list. There are multiple ways of getting the data from this method. </p>
  
  <p><li>Get by crewId only</li>
  <li>Get by shiftDate only</li>
  or
  <li>Get by crewId and shiftDate</li></p>
  
  <p>Do you (1) Mark the crewId and shiftDate as optional? </p>
  
  <pre><code>public HttpResponseMessage Get(string crewId = null, string shiftDate = null, int offset = 1, int limit = 10)
  </code></pre>
  
  <p>and then have bunch of if statements to check what is filled and what is not filled to be able to do actions</p>
  
  <pre><code>if(crewId != null &amp;&amp; shiftDate == null){
    // Get by crewId
  }else if(crewId == null &amp;&amp; shiftDate != null){
    // Get By shiftDate
  }else if(crewId != null &amp;&amp; shiftDate != null){
    // Get By crewId and shiftDate
  }
  </code></pre>
  
  <p>To me this looks crazy to do especially if you have many parameters you would have too many "if" statements in your code.</p>
  
  <p>Do you (2) Have different set of gets?</p>
  
  <pre><code>public HttpResponseMessage GetByCrewId(string crewId, int offset = 1, int limit = 10)
  public HttpResponseMessage GetByShiftDate(string shiftDate, int offset = 1, int limit = 10)
  public HttpResponseMessage GetByCrewIdShiftDate(string crewId, string shiftDate, int offset = 1, int limit = 10)
  </code></pre>
  
  <p>and then you would have your URI Route map to the method </p>
  
  <p><li>.../api/GetByCrewId?crewId=1234</li>
  <li>.../api/GetByShiftDate?shiftDate=1111-11-11</li>
  <li>.../api/GetByCrewIdShiftDate?crewId=1234&amp;shiftDate=1111-11-11</li></p>
  
  <p>is option 2 restful?</p>
  
  <p>Or is there an better options (3).</p>
  
  <p>Both options above will work just making sure I am using best practices and following REST standards. Just seems like I am missing something and hopefully you can put me in the right direction.</p>