0

What i want is to handle an order placed to a server from an android app.

To test things i am using POSTMAN.

I tested it

with the following code.

class newOrder(Resource):
    '''
    this class receives credentials from a post request
    and returns the full menu of the establishment.
    '''
    def post(self):
        try:

            parser = reqparse.RequestParser()
            parser.add_argument('username', type=str, help='Password to create user')
            parser.add_argument('password', type=str, help='Email address to create user')
            args = parser.parse_args()
            _userUsername = args['username']
            _userPassword = args['password']

            return jsonify({'username':_userUsername,'password':_userPassword})
        except Exception as e:
            return {'error': str(e)}

and got this.

enter image description here

So far so good

how can i alter this to work and be tested on POSTMAN and return the following?

{'usename':'foo','password':'bar',
  "order": 
  [
  [1,"ΚΡΗΤΙΚΗ",5,,'tt'],
  [2,"ΣΑΛΑΤΑ","ΦΑΚΗ",6,'tt'],
  [3,"ΣΑΛΑΤΑ","ΚΟΥΣ-ΚΟΥΣ",5,'tt'],
  ]
}

i am having trouble with the list. 'order':[[],[],[],...]

How to i enter that list to POSTMAN parameters?

Also, i am returning it to my self to simply view it. i just want to know that the data was entered properly.

Thank you.

George Pamfilis
  • 1,397
  • 2
  • 19
  • 37

1 Answers1

0

You need to come up with a format in which to send the list. I believe the most common format is just a comma seperated string like so

thing1,thing2,thing3,etc

Pass this in the url like

https://127.0.0.1:3000/postendpoint?arrayParameter=thing1,thing2,thing3,etc

Then on the python end parse it like this

arrayParameter=args['arrayParameter'].split(',')

Obviously you'll have to make sure the format is correct though

edit: If you want to pass a sorta multidimentional array then maybe you need to re-evaluate the way your program works. If you really want to do it then try this.

str = 'a,;1;2;3;4;,c,d'
str = str.split(',')
str[1] = str[1].split(';')
Ryan Weinstein
  • 7,015
  • 4
  • 17
  • 23