I am writing a REST api with Flask, which should create a Dictionary of Dictionaries, e.g.
Dictionary = {
dict1 = {},
dict2 = {}
}
I would like each dict to be filled with individual values, and I would like to fill both dicts in one request, if possible.
So far I have been testing my code with curl requests, and it seems like it is almost there... except for that both dicts are being filled with the same collection of values.
api.py
dictionary = {}
@app.route('/launch', methods=['POST'])
def launch():
gw_type = request.json['type']
for t in gw_type:
dictionary[t] = {
'client': request.json['client']
'band': request.json['band']
'password': request.json['password']
return jsonify(**dictionary)
Curl request
curl -H "Content-Type: application/json" -X
POST -d '{"type":["type1", "type2"], "client":["test1", "test2"],
"bands":["ABCD", "ABC"], "password":["pass", "pass2"]}'
http://localhost:5000/launch
Output
{
"type1": {
"bands": [
"ABCD",
"ABC"
],
"client": [
"test1",
"test2"
],
"password": [
"pass",
"pass2"
]
},
"type2": {
"bands": [
"ABCD",
"ABC"
],
"client": [
"test1",
"test2"
],
"password": [
"pass",
"pass2"
]
}
}
If it is possible, how would I go about creating the multiple dictionaries ('type'), so that each TYPE has it's own unique values for 'client', 'band' and 'password' in one curl request?
Thanks