From what I understand, the web api controller will automatically convert the json request and display the parameters, so it's best to create your own class
Yes. If the data sent with the request can be mapped to an object, the Web API will convert the JSON or XML object to a class object.
If you want your json data to fall inside the object in your method, first determine the class in which your json data will be stored.
public class UserListRequest { public int UserId { get; set; } public string CsvListOfIds { get; set; } }
Later change your method signature to get an object of this class:
[HttpPost] public List<User> GetUserList(UserListRequest obj) { List<User> list = new List<User>(); list.Add(new User { ID = obj.UserId }); list.Add(new User { ID = obj.UserId + 1 });
Remember to use the [HttpPost]
attribute. There should also be one post method that you can comment on the already provided Post
method in the controller. (If you want your controller to have multiple send methods, see this question )
You can send a request through jquery or Fiddler (or in any other way). I tested it with Fiddler. You can see Web API Debugging via Fiddler
Once your controller is configured, then create a project and run it in debug mode. Start Fiddler and go to the composer.
Paste your controller URI (from IE / Brower) into the address bar and select Post
as the Http method. Your URI will look like this:
http://localhost:60291/api/values/GetUserList
In Fiddler Composer -> Title Header, specify
Content-Type: application/json
In Fiddler Composer -> Request Body, specify your JSON
{ "UserId": 1, "CsvListOfIds": "2,3,4,5" }
(You can also create your C # template class from json using http://json2csharp.com/ )
Put the debug point in your method in the controller, and then in Fiddler Hit Execute
, you will see that your debug point in Visual studio is Hit, and the data is populated into the parameter. 
You can later return a List<User>
and you will see the answer in Fiddler.
[{"ID":1},{"ID":2}]
I temporarily created a User
class, for example:
public class User { public int ID { get; set; } }
Hope this helps.