Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am developing web api's using restfull web services.
How to use path param and query parm in the web api's.
Project type is asp.net mvc 4
The task is to use single method to do multiple task.
e.g public Student(string id)
{
var student=listOfStudents.find(st=>st.Id=id);
return student;
}
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jan-15 2:17am    
Which query? Database? URL parameters ("query string")? What's the problem?
—SA

1 solution

You shouldn't. Use single method to do single task with meaningful names.

If you absolutely have to, add parameter that describes the action i.e. public Student(string id, ActionEnum action) { /*whatever*/} where ActionEnum will list available actions in some meaningful way i.e. ActionEnum.Insert, ActionEnum.GetStudent, ActionEnum.GetStudents etc...

However, whatever you put into that enum should actually be separate method.
Note that single method will not simplify, but complicate the service.

True, you will have only one method, but the callers will have to know which parameters have to go for action. And also the method will get large with switch statements and maybe some code duplication.

Instead have a methods
GetStudents {return listOfStudents)
GetStudent (string id) { return listOfStudents.find(st :> st.Id = id)
InsertStudent (Student s) {}
etc...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900