title: Best practice for passing enum params in Web API
body: <p>I have a RESTful Web API project, and I have 2 different Enum scenarios that I'm unsure of re best practice.</p>
  
  <p><strong>Scenario 1 : Straightforward Enum Param</strong></p>
  
  <p>My API method requires a parameter called <code>ruleType</code>, with valid values being <code>EmailAddress</code> and <code>IPAddress</code>.
  My enum within the Web API project looks like this:</p>
  
  <pre><code>public enum RuleType
  {
      None = 0,
      EmailAddress = 1,
      IPAddress = 2
  }
  </code></pre>
  
  <p>My question for this scenario is, should I use <code>?ruleType=EmailAddress</code> in my request to the API (which automatically binds that value to my <code>RuleType</code> property within the API method)? If so, how best to validate that the <code>RuleType</code> param sent, is a valid RuleType Enum value?</p>
  
  <p><strong>Scenario 2 : Multiple Enum Values for a Single Param</strong></p>
  
  <p>My API method has an optional <code>fields</code> param, which is allows you to specify any additional data that should be returned. E.g. <code>&amp;fields=ruleOwner,rule</code>. This would return those 2 extra bits of data in the response.</p>
  
  <p>I have an enum in the Web API project which relates to each possible <code>field</code> that may be requested, and at present, I am splitting the comma separated fields param, then looping through each string representation of that enum, parsing it to the equivalent enum, resulting in a list of Enum values which I can then use within my API to retrieve the relevant data.</p>
  
  <p>This is the Enum:</p>
  
  <pre><code>public enum OptionalField
  {
      None = 0,
      RuleOwner = 1,
      Rule = 2,
      etc.
  }
  </code></pre>
  
  <p>What would be best practice here? I was looking into bitwise enums, so a single value is sent in the API request which resulted in any combination of <code>fields</code> but didn't know if this would work well with a Web API, or if there's generally a better way to go about this?</p>