0

I am using a System.Web.Http.ApiController in my application. One of the functions I need is to have an admin screen with a button on it that will initiate some method on the controller to move data from one table to another. The action should complete within a few seconds. There need be no parameter sent to the action and I assume that I can do this with a normal HTTP call to a method on the WebAPI controller.

However what type of call should this be? GET, POST, PUT ? None of these really seem to fit so I would appreciate some advice.

4

4 回答 4

3

If you are "moving" data then the operation is "unsafe" and "non-idempotent" therefore POST correctly describes those semantics.

于 2013-11-05T12:47:17.720 回答
1

Given REST is based on resource access, neither GET, POST or PUT apply. You're retrieving nor sending resources. You're, frankly, calling a Remote Procedure Call.

You can however expose this RPC as a resource, though one that only allows one method. It's up to you to name and implement this. I'd say you POST to /Admin/BeginCopyingData/.

于 2013-11-05T12:45:02.680 回答
1

I would go for a POST or PUT - it doesn't really matter.

Wait, what?

Honestly, if it is to kick off some internal admin system function rather than to add an entity to a truly RESTful API then I would advise you to avoid getting caught up in HTTP semantics, as you aren't doing REST.

You don't even need to use Web Api, you could just have the form on the page post back to a standard action method on your MVC controller.

于 2013-11-05T12:47:09.663 回答
0

Given that POST in REST can be interpreted as "process" , I would go for POST. Also, POST is not idempotent so you can do pretty much whatever you want with it.

于 2013-11-05T12:49:53.813 回答