Click here to Skip to main content
15,444,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a ASP.net 1 page that queries an API provider which works as expected but I want to add APIs from other providers on the same page. How can I achieve this in VB.NET?

What I have tried:

Below code works with just one API:
VB.NET
Dim doc  As New XmlDocument()
doc.Load("http://api.test.com/1.0/products.xml;q=paris?token=SAD345A8718524374ZXZXCVMSHWEU8")

Dim nsManager As New XmlNamespaceManager(doc.NameTable)
nsManager.AddNamespace("ns1", "urn:com:test:pf:model:xml:output")
nsManager.AddNamespace("ns2", "urn:com:test:pf:model:xml:common")
Dim nodes As XmlNodeList = doc.SelectNodes("//ns1:products/ns1:product", nsManager)

Dim dataSource As IEnumerable
dataSource = From node As XmlNode in nodes
Select Name = node.SelectSingleNode("ns2:name", nsManager).InnerText, _
Description = node.SelectSingleNode("ns2:description", nsManager).InnerText, _
Image = node.SelectSingleNode("ns2:productImage", nsManager).InnerText, 
Posted
Updated 6-Dec-19 11:19am
v2
Comments
Richard Deeming 3-Dec-19 14:23pm    
How you interact with an API will differ depending on the API you're calling. There's no "one size fits all" solution to calling an API.
hm9 24-Dec-19 15:48pm     CRLF
The issue I have isnt with getting the data. The data can be viewed but it cant be bound to the repeater properly, It always binds the last one so it overwrites the first one. So in the code below, both datasources 1 and 2 show data but not simultaneously. if I swap the order, it always shows the second one, so it is the binding that is the issue. Need to find a way to add both datasources 1 and 2 to another item and then bind that item ? Dim dataSource1 As IEnumerable Dim dataSource2 As IEnumerable rpMyRepeater.Datasource = datasource1 rpMyRepeater.Datasource = datasource2 rpMyRepeater.Databind()
hm9 3-Dec-19 15:04pm    
The above example is how I m interacting with one API. Is there a way to add another API to the above code?
ZurdoDev 4-Dec-19 9:05am    
Write code to do another one. Why are you stuck?
j snooze 3-Dec-19 17:30pm     CRLF
Are the results of each response layout EXACTLY the same from each API? Otherwise you will have to maybe create a class with the properties of the values you want and fill an ienumaerable list from the results of each api. Since we don't know anything about the API's you are calling its tough to answer the question.

1 solution

Ok I tried this method by loading 3 APIs in this way:


Dim doc As New XmlDocument() 
dim doc1 = ("AP1")
dim doc2 = ("AP2")
dim doc3 = ("AP3")


doc.Load(doc1)
doc.Load(doc2)
doc.Load(doc3)

But this always load the last one API3 and ignores the first 2. Is there a way to get to load all three instead of only the third one?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900