0

I'm looking to pass a list of integers (ids) into a .NET core WebApi in the same manner that stack overflow does:

https://api.stackexchange.com/docs/questions-by-ids

Is this possible to strongly type the parameter or do I just accept a string and parse it?

Just to be clear I want the url to be in the format http://myapi/products/1,2,3,4,5 or http://myapi/products/1;2;3;4;5

as I would like the URL to be clean like the stackoverflow link I posted

Mark
  • 2,392
  • 4
  • 21
  • 42
  • That's not comma or semicolon formatted – Mark Aug 27 '18 at 18:33
  • [This answer](https://stackoverflow.com/a/17553324/2030565) does a split and parse. – Jasen Aug 27 '18 at 18:44
  • That's looking a bit better, looks like it might be what I have to go with if there isn't an out the box solution – Mark Aug 27 '18 at 18:49
  • `var ids = input.Split(',').Where(i => int.TryParse(i, out tmp)).Select(int.Parse).ToList();` Just an example, though calling a `Parse` method twice is redundant and it would be better to just capture `tmp` in a loop. Not sure if it's safe to `Select` it, though, which is why I called `Parse` again in this example. – Rufus L Aug 27 '18 at 20:15

0 Answers0