1

I am building a small Nancy webapp which would do CRUD operations on a table. It uses GET, POST and DELETE verbs. I want to have a link in the web page to call the delete method. Using a "anchor" tag would use the GET method, by default. I am not comfortable with changing the webservice to use GET verb to do delete operations as it would break RESTful concept. What is the best practice in such situation?

4

2 に答える 2

3

記述/状態変更操作にGET動詞を使用しないでください。そのため、DELETEまたはPOSTを使用するのが方法です(この場合、DELETEは意味的に正しいです)。

javascriptを使用すると、アンカークリックイベントをフックして、DELETE動詞を使用してリクエストを実行できます。

Jqueryのajaxメソッドを使用した小さなサンプル:

<a href='/deleteAction/myId' class='deleteLink'>Delete me</a>

$('.deleteLink').click(function(e){
   e.preventDefault();
   $.ajax({
     url: $(this).attr('href'),
     type: 'DELETE',
     success: function(result) {        
  }});
});
于 2012-06-19T07:11:11.793 に答える
1

You should not use GET verb for DELETE, GET is considered to be a safe operation and is not supposed to change your application's state.

You should use DELETE and can also use POST (because some firewalls do not allow DELETE).

于 2012-06-19T07:06:05.477 に答える