Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/459028504898977792
Source Link
Victor Ronin
  • 669
  • 2
  • 5
  • 14

How to provide a service with RESTful API?

Generally speaking, RESTful API's are very good for representing resources and collections of resources.

And we are good, if we work with resource.

However, what should be done, when you need to expose API which does an action which doesn't create/update or delete a resource.

Couple of examples:

  • You have an algorithm (as example add two numbers)
  • You have an action which uses external system (as example send an email).

I saw two approaches:

Represent an action as a subresource

POST http://example.com/resource/item17/sendemail

On one hand, it's straightforward. On other hand, it start smelling SOAPy (read RPC calls).

Represent an action as a standalone resource

POST http://example.com/emailsender

This looks more RESTful. However, it doesn't feel right too (only one of CRUD actions is implemented). This resource actually doesn't have a representation.

I am not sure, may be there are other methods which I have missed.

The question is - "Is there a consensus on this subject? What is the preferred way to do it?"