Best practice for passing enum params in Web API

前端 未结 4 1664
迷失自我
迷失自我 2021-01-07 16:30

I have a RESTful Web API project, and I have 2 different Enum scenarios that I\'m unsure of re best practice.

Scenario 1 : Straightforward Enum Param

4条回答
  •  天命终不由人
    2021-01-07 17:07

    it is a best practice to make the URI "human readable". so i can also understand why you using Enum as a string. But as HristoKolev said you have to write a custom Model Binder.

    In fields i think you should not use an combination of enums. because it is difficult to understand. perhaps you can create an combination of enum as enum entry

    public enum OptionalField
    {
        None = 0,
        RuleOwner = 1,
        Rule = 2,
        RuleAndRuleOwner = 3,
        etc.
    }
    

提交回复
热议问题