How to load multiple API responses in one object

3 days ago 5
ARTICLE AD BOX

I need to load a series of API responses into one object because the item limit in the API is less than the total items. Currently I'm reading the response into a json string and reurning it once.

public static OrdersResponse GetAllOrders() { OrdersResponse result = new OrdersResponse; int limit = 500; int offset = 0; string url = "https://myurl123456/?limit={limit}&offset={offset}"; HttpWebRequest httpWebRequest = CreateAPIRequest(url); using (HttpWebResponse response =(HttpWebResponse)httpWebRequest.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string json = reader.ReadToEnd(); DebugLogResponse<OrdersResponse>(DebugMode, ServiceName, "GetOrders", json); result = JsonConvert.DeserializeObject<OrdersResponse>(json); } } return result; }

Can I wrap this in a while loop with a new url while result.hasmore is true and and the new json lines to the result or is there a better way to do that?

Read Entire Article