0

I'm using Django rest framework and on a POST request need to make an external request to a SOAP server which outputs weather reports. I receive something like this to my API

{
  'city': 'Manchester',
  'country': 'GB',
  'locality': 'EU'
}

Now this is the data I get. Serializing this data is fine and I get that. However since the SOAP address requires me to make a request within the following format I get confused.

I haven't really tried anything but looking for a best solution in this.

{
   'geopgrahpy': {
         'country': 'GB',
         'city': 'Manchester',
   },
   'locality': 'EU',
   'userID': '123',
   'password': 'xxxxx'

}

My question is what would be the best solution? Manually building a util function which will return the userID, password (from the request) or build another serializer matching to the soap server needs.

Also bear in mind I know SOAP is XML but the Zeep library converts it to and from XML.

  • Hi @user2826425, what exactly do you want to do, your question is not clear. Do you have some models or you just want to extract data. – unlockme Jul 31 '19 at 15:27
  • I would like to extract the data and make a SOAP request but unsure if I need to serialize this or not – user2826425 Jul 31 '19 at 15:28
  • Do you know about nesting of serializers? @user2826425 – unlockme Jul 31 '19 at 15:29
  • I do. However as these are different in that sense, shall build nested serializer one for incoming one for the soap request or shall I just use a util function with dynamic keys? – user2826425 Jul 31 '19 at 15:36
  • I can see that the nested part of the second dictionary is not exactly equivalent to the first one. which has an extra parameter . In this situation a function would be better to extract the dynamic data. You are probably better off starting with the nested serializer as it provides for you extra functionality such as validation. You have to be very careful with any external data, you could get hacked. – unlockme Jul 31 '19 at 15:44
  • have you been able to resolve your problem. – unlockme Aug 02 '19 at 09:16
  • I haven't unfortunately. If I wanted to return something like the following ``` – user2826425 Aug 02 '19 at 13:34
  • I haven't unfortunately, the key issue is this. I have a List of objects. I want to return them list this `{ locatility: {['city': 'xxxx', 'country': 'GB'}]}}` – user2826425 Aug 02 '19 at 13:49
  • Give me a pastebin link of sample dataset and expected output and I will see what I can do. – unlockme Aug 02 '19 at 16:02
  • https://stackoverflow.com/questions/57327970/drf-nested-serializer-return-in-extra-dictfield – user2826425 Aug 02 '19 at 16:38
  • I wanted to let you know your question would be quickly down voted. You have got to be patient. If you ask a question, you should always post an example of what you have done and how it failed. Dont post another question. You can edit the current one. Please edit and include some code snippet (WHAT YOU HAVE DONE). – unlockme Aug 02 '19 at 17:47

0 Answers0