0

I am working on a web api project (back end) and I am searching for some more optimized way to get multiple parameter from front end. There are numerous ways like

i) name each parameter in action parameter stack
ii)  extract from request body like Request.Content.ReadAsStringAsync().Result;
iii) define complex types (model) and use that type to receive values. like MyAction(UserLog log)

I have to create hundreds of functions which may take variable number of parameters. I don't want to use first option above, it is hectic for large data. The second is confusing as no one can predict what to post. The third one forces me to create hundreds of input models. So is there any better way to do so?

Lali
  • 2,816
  • 4
  • 30
  • 47
  • Check out [this answer](http://stackoverflow.com/a/33345873/65775). By using a custom parameter binding, you can pass multiple POST parameters to any API method. – Keith Oct 26 '15 at 12:40

1 Answers1

0

You could try using a form data collection Its basically a Key Value Pair which allows for an element of genericness.

Edit - another link

Another option would be to apply dynamic object parameters on your Post Verbs.

E.g.

 public string Post(dynamic value)
 {
    string s = "";
    foreach (dynamic item in value)
    {
        s = s + item.content + " ";
    }
    return s;
 }
DotNetHitMan
  • 931
  • 8
  • 20
  • The problem with this approach is, the front end developer will not know what to pass. OR in other words, API developer need to tell every time that "Now I also need customer's gender". The method above doesn't show any thing about this change. – Lali Apr 22 '15 at 08:53