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 aWebException
, and you're sure the address is valid, then there was some issue in making your query. You can check theResponse
andStatus
properties of the WebException to learn more.