I would like to get some input on a script library I'm writing to wrap ERP APIs and make them easy to use from Ignition. Right now, I have a class of type Transactor that will have methods within itself for specific requests. For instance, the stripped down version looks like this:
class Transactor():
def __init__(self, transType):
self.transType = transType
def getWorkOrder(woNum):
# make http call to endpoint to get work order
def reportConsumption(item, quantity):
# make http call to endpoint to post consumption
... etc ...
My question revolves around how often I should be creating an httpClient
whenever I have this paradigm. I think I can probably create one httpClient
in the constructor of the class and then use that instance for any methods. That way, on the consumer side, I can do something like
erpObj = shared.erp.Transactor('erpName')
erpObj.getWorkOrder('abc123')
...
erpObj.reportConsumption('a123312', 12.9)
The other way that I could do this (but seems like a bad idea) is to create a new httpClient
within each method in my class. This seems unnecessary, but I don't fully understand the implications if I don't do it this way (this is the simpler way to do it in my mind, and how I built out a POC).
Any input / advice would be very helpful!