views:

36

answers:

3

I designed a class which creates XML for a POST in order to call an API call to a third party API. The class has helper methods; One to form the HttpWebRequest and then one to send it. My question is this:

Should the response (which ultimately I'm going to shove into an XMLReader and parse it to get the values) be returned as an HttpWebResponse, an XMLReader or what? And should that response be returned by the Send HttpWebRequest method I have or simply set to a property in my APIRequest.cs class that is doing the sending? Or should I pass that HttpWebResponse or XMLReader (if i decide to first shove that response into a reader instead) to an entirely different class called APIMethodResponse that holds the values that came back in the Response?

I'm thinking about SOLID and just basic class design here. I'm not sure which way to go with it in terms of handling the response that comes back from the API method call/request that I make with my APIRequest.cs class.

Note: The APIRequest.cs class is really more specfic such as UpdateCustomerRequest.cs since I'm calling the API method UpdateCustomer for example. So the XML I create for the POST is created via a method that creates the necessary nodes and data to send as the POST for the UdpateCustomer method call

+1  A: 

You should not return the HttpWebResponse. This is internal to your API calling framework, and not relevant to the caller.

I would either stay basic and return the raw XML (which can then be parsed in several ways depending on the caller's requirements), or I would go all the way, parse it and return the return value/out parameters inside.

Keep in mind, the caller would want, as near as possible, to call API methods and get the return values without dealing with the wiring involved.

Tor Haugen
+1  A: 

Return an XmlReader. You can do anything at all with an XmlReader - load into an XmlDocument, use as input to XslCompiledTransform, etc. It's the least common denominator of the XML APIs.

BTW, do you ever create the HttpWebRequest but then not send it?

John Saunders
A: 

Thanks, I went with the reader, makes sense.