Web API httpget with many parameters
I am trying to create my first REST service using WEB API to replace some
of my postbacks in a web forms asp.net project. In the web forms project,
when I browse to a new web page, I always get an ASP.net Application
variable and a querystring value that helps me determine which database to
connect to. In this old app, it connects to several different databases
that all have the same schema and database objects but the data is
different in each database
I am not sure the best way to pass these variables to a REST Service or if
they should be part of the route or some other method.
So in a REST method like the one below
// GET api/<controller>/5
public string GetCategoryByID(int id)
{
return "value";
}
I can get the category id and pass that to my database layer, but I also
need the two variables mentioned above. I will need to obtain these
variables in every call to my REST api in order to access the appropriate
database. Should I use something like the following:
// GET api/<controller>/5
public string GetCategoryByID(int id, string applicationEnvironment,
string organization)
{
return "value";
}
Or should they be part of the route with something like this:
api/{appEnvironment}/{organization}/{controller}/{id}
This seems like a simple problem, but I am having trouble figuring out a
solution.
Thanks!
No comments:
Post a Comment