Wednesday 15 June 2011

rest - How to add multiple Get Post and Delete methods in RESTful Service -


I'm new to Aristi services and would like to know how we can add as many gate / post / delete methods.

For example we are to follow the law: -

  GetAllUsers () GetUserByID (int id) GetUserByName (string name)   

Similarly, delete methods: -

Post / Put methods: -

  PutCreateDefaultUser (PTI)  < / p> 
  [deleted user () DeleteUserByID (int id) DeleteUserByName (string name) ) PutCreateUser (users) PutCreateMultipleUsers (user] user)   

In the case of the above, receive / delete / post / methods How to define. Is this name itself called, which is found / deleted / put / put

How is the Yuri template set for each other also?

What will be the URI of each method?

Note: I am using the MVC4 .NET Web API project, I WCF

Indicate one of your examples is based on comfort resources. Each resource has its methods to get, update, insert and delete. If you have said anything in your question, then you will be in your ASP.NET API. Can not create any such problem: (But make sure it does not no REST) ​​

UserController

  [RoutePrefix ("API / v1" root ( "them")] public HttpResponseMessage GetAllUsers () {...} [HttpGet] [root ( "user / {id: integer}")] public HttpResponseMessage GetUserByID (int id) {...} [HttpGet] [ Root ("user / {name: string}")] Public HttpResponseMessage GetUserByName (string name) {...} [HttpDelete] Public HttpResponseMessage DeleteAllUsers () {...} [HttpDelete] [Root ("User / {ID: Integer} ")] Public HttpResponseMessage DeleteUserByID (Integer ID) {...}}   

With HttpAttributes, you may want to have many HTTP feeds. Simply put the attribute on top of the action and you're doing well to go; also it applies to that methods can be asked only by using that HTTP function, if deleted in the above, if If you call with a GET verb, then you will not get anything. (Action will not be available)

If you want, you can also specify a custom route for your action, for example, your call will be GetUserByID:

GET: < / P>

No comments:

Post a Comment