WebDev module when to use doPut vs doPost

I’m just getting started with the WebDev module and have a project where an external system will create an HTTP request by supplying a tag path and tag value and Ignition will update the tag accordingly. The tag path and value will both vary. Here is my code so far.

def doPost(request, session):
	import time
	tagPath = request['params']['tagPath']
	tagValue = request['params']['tagValue']
	tagVal = system.tag.read(tagPath).value
	return {'json': system.util.jsonEncode(tagVal)}

It seems to work fine with the doPost and doPut methods. But which one should I use?

I have searched the web and this seems to be a common topic. Most posts on this forum say doGet and doPost handles almost all cases so I’m leaning towards doPost. Stack Overflow mentions that PUT is idempotent…which I also had to google and still don’t really understand but it has to do with being able to send (or re-send rather) the same request and it’s processed exactly the same as it would be the first time that it was sent.

There’s also mention of POST being good for a “list of questions” and PUT for a “single question”. Not sure how that relates to my need with a tag path and value.

But I’m so new to this that I still don’t really know the best practice. Any thoughts?

In reality it probably doesn’t matter, but it seems to me like PUT would be more appropriate given the request parameters and function (updating an existing tag value) you’ve described. You’re updating an existing tag value, not creating a new tag and value.

1 Like