the main requirement is the the 3rd party url support CORS for your site. because the browser will restrict access (as blazor is just using javascript to make ajax calls). if the 3rd party does supports CORS, then you will need a server proxy.
How do I embed a 3rd Party API service inside my ASP.net Blazor Web Assembly
Hello,
I was in the process of making a website that features a UI displaying information from a 3rd Party API
When the client refreshes the page: Client Browser requests XML from 3rd Party API -> Client then parses XML Response -> Client then outputs the data (All Asynchronously)
As far as I have read in the Microsoft Learn they set up their own API service using their own data from the server, but since my XML is rather large calling an API which then calls another API would result in a large download time overall..
How should I implement the request to a 3rd Party API directly?
I have fully developed the backend already in C#, the request looks something like this:
public string XMLRequest;
public static async Task<string> executeRequest()
{
HttpWebRequest client = (HttpWebRequest)WebRequest.Create(3RDPARTYURL);
client.ContentType = "application/soap+xml";
client.Method = "POST";
using (Stream postStream = await client.GetRequestStreamAsync())
{
byte[] postBytes = Encoding.ASCII.GetBytes(XMLRequest);
await postStream.WriteAsync(postBytes, 0, postBytes.Length);
await postStream.FlushAsync();
}
Task<string> Response;
using (var response = (HttpWebResponse)await client.GetResponseAsync())
using (Stream streamResponse = response.GetResponseStream())
using (StreamReader streamReader = new StreamReader(streamResponse))
{
Response = streamReader.ReadToEndAsync();
}
return await Response;
}
Ryan