I'm not an experienced Python programmer but I feel my solution to this problem isn't right, I think there is a better way to deal with this problem in Python.
In this case, this is using Hug API but that's probably mostly irrelevant.
Let's say the code is like this:
@hug.get_post('/hello')
def hello (name)
print(type(name))
return name
When a request is sent with one instance of the name parameter, the hello function gets a str - as in:
POST /hello?name=Bob
But if the request is sent multiple name parameters, the method receives a list of strings, as in
POST /hello?name=Bob&name=Sally
If I write the method like the following:
@hug.get_post('/hello')
def hello (name: list)
print(type(name))
return name
Then the single parameter becomes a list of characters. I.e. ['B', 'o', 'b']. But this works fine if there is multiple instances of the name parameter (e.g. ['Bob', 'Sally'] )
So the way I solved it right now is by adding this code:
@hug.get_post('/hello')
def hello (name)
names=list()
if type(name) != 'list'
names.append(name)
else:
names=name
return names
This works, but feels wrong. I think there is a better way to do this but I can't figure it out at the moment.