0

I want to turn a request like

foo.com/missions?type=flight&location=USA

into a multidimensional array or a map so that I can use them later in a filter.

The names of the parameters and the number of parameters are all variable.

This is in C# using WEB API.

To clarify:

[Route("missions")]
[HttpGet]
public HttpResponseMessage SearchMissions(Dictionary<string, string> filters) // Dictionary may not be the most appropriate; I'm new to C#
{
    ...
}

The keys are type and location and the values are flight and USA.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
tenmiles
  • 2,521
  • 3
  • 18
  • 20
  • you can via POST but i doubt when using GET – Anonymous Duck Jun 08 '16 at 09:49
  • Possible duplicate of [REST API Best practice: How to accept list of parameter values as input](http://stackoverflow.com/questions/2602043/rest-api-best-practice-how-to-accept-list-of-parameter-values-as-input) – Alexandru Marculescu Jun 08 '16 at 09:56
  • @AlexandruMarculescu I have reviewed that other question and, while good information, does not answer my question. I need a collection that contains not just the value of the input parameters, but the names of the input parameters as well. The name of the collection that would be referenced in the code would be more like "params" and not type or location. – tenmiles Jun 08 '16 at 11:10

1 Answers1

1

From what you are describing, you can get the request's query and parse it into key value pairs that you can use to extract the information you need.

[Route("missions")]
[HttpGet]
public HttpResponseMessage SearchMissions() {

    //Get the parsed query string as a collection of key-value pairs.
    IEnumerable<KeyValuePair<string, string>> filters = this.Request.GetQueryNameValuePairs();

    //...
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472