Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it dangerous if a web resource POSTs to itself?

Tags:

http

While reading some articles about writing web servers using Twisted, I came across this page that includes the following statement:

While it's convenient for this example, it's often not a good idea to make a resource that POSTs to itself; this isn't about Twisted Web, but the nature of HTTP in general; if you do this, make sure you understand the possible negative consequences.

In the example discussed in the article, the resource is a web resource retrieved using a GET request.

My question is, what are the possible negative consequences that can arrive from having a resource POST to itself? I am only concerned about the aspects related to the HTTP protocol, so please ignore the fact that I mentioned about Twisted.

like image 890
npclaudiu Avatar asked Jun 06 '26 11:06

npclaudiu


2 Answers

The POST verb is used for making a new resource in a collection. This means that POSTing to a resource has no direct meaning (POST endpoints should always be collections, not resources).

If you want to update your resource, you should PUT to it.

Sometimes, you do not know if you want to update or create the resource (maybe you've created it locally and want to create-or-update it). I think that in that case, the PUT verb is more appropriate because POST really means "I want to create something new".

like image 141
systho Avatar answered Jun 08 '26 01:06

systho


There's nothing inherently wrong about a page POSTing back to itself - in fact, many of the widely-used frameworks (ASP.NET, etc.) use that method to handle various events that happen on the client - some data is posted back to the same page where the server processes it and sends a new reponse.

like image 22
xxbbcc Avatar answered Jun 08 '26 02:06

xxbbcc