views:

38

answers:

2

Hi i am writing a restful webapp using Spring 3. Part of the app is a form which when submitted triggers the sending of an email with various application log files attached. I'm not sure whether i should handle this form submission as a 'POST' or a 'PUT'.

My issue is that structurally the process would seem to be idempotent (and therefore a candidate for a PUT) - the same request submitted n times with the same data will always send an email with the same textual content, with the same files from the same file system locations attached.

However the content of the attached files is likely to be different for each execution of the request.

Is the content of these files beyond the scope of what i should be interested in when deciding on PUT or POST? Am i missing the point here completely?

Any thoughts would be much appreciated

Many thanks in advance!

+1  A: 

I would definitely go for POST as each time you post your data a new email will be sent/created. PUT is mostly used to edit existing entities.

Martijn Laarman
A: 

Can you do a GET on the url that you did the PUT on to return the same resource? If not then use POST.

It matters less what the server does after the request. What is important is that the behaviour is consistent to the client. If a client PUTs a resource, it expects to be able to GET it afterwards. If you make the client do POST then the client has no expectations, unless you return a 201 in which case it expects the Location header to contain the newly created resource.

The issue of sending multiple emails if you PUT twice is debatable. As long as the number of emails sent is not exposed to the client then you are not violating the behaviour of the uniform interface. However, someone else in the system may get confused by the fact that they are receiving multiple interfaces.

Darrel Miller