I have an application which gets data from an API:
string jDoc = webclient.DownloadString(url);
Before I make this call, however, I need to make sure the API is available.
How would I go about doing this?
Should I just use a TRY/CATCH
block or is there a better way of doing this?
A Web API is like any other web page, so this comes down to "How do I see if a webpage is responding?"
As per the documentation, sure, just use try/catch
. If there's a WebException
, and you're sure the address is valid, then there was some issue in making your query. You can check the Response
and Status
properties of the WebException to learn more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With