Question

I'm writing a method to an API. The Unirest post call is of the form

response = unirest.post("http://some.url.org/arg",
                       {
                          "X-Mashape-Authorization": "authCode"
                       },
                       {
                          "key1": "val1",
                          "key2": "val2",
                          "key3": "val3",
                          "key4": "val4"
                       }
                       );

key1 is mandatory, while key2, key3, and key4 are optional. I want to have one method called

update(v1, v2, v3, v4)

which will create the params dictionary, add it to the POST, then send it out. The first part, I've got down. While writing it, I got the nagging feeling that dictionaries aren't sorted. One quick test, and it proved I was right. Since it's an API, I'm fairly sure they require the fields to be in the right order. Is there any way I can insert the parameters into the dictionary in the correct order? I can't use an OrderedDict, as it's a non-hashable type.

Was it helpful?

Solution

You don't have to worry about sorting for an API. You are passing a key-value object so the api should be accessing you passed args with a dict["key1"] or its equivalent for a hash map.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top