RESTful actions/services that don't correspond to an entity?

Viewed 2673

I like RESTful for its simplicity and how it avoids the cruft of normal 'enterprise' systems like SOAP, or the binary-hardness of DCOM and RPC.

But REST seems more suited to database entities than more abstract services. I was wondering if you could advise me on how you'd do these situations:

For example, suppose I have a RESTful web-service for a normal database system (say, a dairy shopping site), so I'd have /products/eggs/battery and /products/milk/skimmed

Doing an INSERT would be achieved by making a POST to /products/eggs.

But how would you do a "clear all" command? The DELETE verb is only suitable for single entities. And a "DELETE /products/milk" implies deletion of the "milk" product category itself rather than just all products within the milk category. And what if you want to accomplish both?

Another question I have relates to web-service actions that are not related to an entity. For example, if I'm designing a web-service for a password database, I'd have operations like "GET /passwords/stackoverflow.com" which is fine, but I would also have operations to disable the website in case of intrusion detection. Under the 'old school' web-service model I'd have a method simply named "disableWebsite", however I can't create a HTTP verb called "DISABLE" and a resource called "/website" (so the request would be "DISABLE /website"). What's the solution here?

Finally, how do you reconcile HTML Forms with RESTful? Web forms can only make GET requests using querystrings or POST. If I have a search form I want it to request "/products/search/{query}" but right now the request would look like "/products/search?query={query}".

3 Answers
Related