Need a recommendation on how to handle this. I have a python lambda function that accepts in json. There could be 10 different types of payload.
For example:
{
"animalType": "dog",
"name": "josie",
...
}
another app can send in:
{
"animalType": "cheeta",
"name": "cheetos",
...
}
another app can send in:
{
"furniture": "chair",
"storeName": "Freedom furniture",
...
}
I want to apply different logic based on the payload that is sent in.
Do you think it’s wise to:
if "animalType" in json.dumps(event):
...do something
elseif "furniture" in json.dumps(event):
...do something
else
...do something
any thoughts? the …do something area could be pretty long and I want to consider these separate modules, so should I call another function?
2
Answers
so just store the output in a data struct. Core Dev solution here:
Now that you have the data in a data_list you can loop through it and use constants to get back the logic you need:
you can repeat this logic as needed. One of the most powerful ways to get started with data structure, design algorithms and OOP.
I say OOP as this logic can be optimized by not just adding functions to deal with new dynamic use case and future requirements, but the above logic can also be refactored to use classes using OOP concepts.
you will evolve as you learn and explore:
happy coding:)