locked
What can I do to get check if my POST APIs are working or not for monitoring multiple APIs RRS feed

  • Question

  • User-1971168174 posted

    Hi Support,

    I need to monitor many APIs to check weather all GET and POST APIs are working or not on frequent intervals...Say every 1 hr.

    For GET APIs right now i can think checking by below approach:

     static bool IsAddressAvailable(string address)
            {
                try
                {
                    System.Net.WebClient client = new WebClient();
                    string result = client.DownloadString(address);
                    client.DownloadData(address);  
                    
                    return true;
                }
                catch
                {
                    return false;
                }
            }

    What can I do to get check if my POST APIs are working or not?Please help me with code sample.

    Thanks in Advance!

    Tuesday, May 12, 2020 8:35 AM

Answers

  • User475983607 posted

    If you are trying to learn how to post to an Web API end point then read the links in my last post.   It's super easy with the HttpClient and the links have sample source code.  The community cannot provide accurate code as we have no idea how your Web API application works.  Usually there's security and a data model involved in an HTTP post.  

    Thanks Mgebhard!

    We have 100 + GET and POST APIs used in various projects.I need to have a dashboard which will show status of these APIs weather all are working or some of them are down.

    As of now I can check GET APIs status by below code (I am not sure if this is the right approach)

    static bool IsAddressAvailable(string address)
            {
                try
                {
                    System.Net.WebClient client = new WebClient();
                    string result = client.DownloadString(address);
                    client.DownloadData(address);  
                    
                    return true;
                }
                catch
                {
                    return false;
                }
            }

    Similarly I am looking for code to check if all my POST APIs are working.

    It's reasonable to assume if a GET request is successful then the Web API is up and running.  Why do you need to check the POST endpoints?  If you are looking for exceptions or unexpected results then look into standard logging and exception handling.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 12, 2020 1:20 PM
  • User-474980206 posted

    generally you want to know if the service is responding (periodic get ping), and if it is logging errors. 

    if the service connects to other services, add a ping that checks access to the other service. you might define a common set of health test apis, that all services implement. this with standardized logging of error should do what you want. call every api for a health test is not typical.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 12, 2020 3:16 PM

All replies

  • User475983607 posted

    What does "working" mean?  Are you trying to check if several applications are running? 

    What can I do to get check if my POST APIs are working or not?

    Can you explain why you need this "ping" approach?  Perhaps logging and exception handing is a better approach.  

    Please help me with code sample.

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

    https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=netcore-3.1

    https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.postasync?view=netcore-3.1

    Tuesday, May 12, 2020 11:34 AM
  • User-1971168174 posted

    Thanks Mgebhard!

    We have 100 + GET and POST APIs used in various projects.I need to have a dashboard which will show status of these APIs weather all are working or some of them are down.

    As of now I can check GET APIs status by below code (I am not sure if this is the right approach)

    static bool IsAddressAvailable(string address)
            {
                try
                {
                    System.Net.WebClient client = new WebClient();
                    string result = client.DownloadString(address);
                    client.DownloadData(address);  
                    
                    return true;
                }
                catch
                {
                    return false;
                }
            }

    Similarly I am looking for code to check if all my POST APIs are working.

    Tuesday, May 12, 2020 12:41 PM
  • User475983607 posted

    If you are trying to learn how to post to an Web API end point then read the links in my last post.   It's super easy with the HttpClient and the links have sample source code.  The community cannot provide accurate code as we have no idea how your Web API application works.  Usually there's security and a data model involved in an HTTP post.  

    Thanks Mgebhard!

    We have 100 + GET and POST APIs used in various projects.I need to have a dashboard which will show status of these APIs weather all are working or some of them are down.

    As of now I can check GET APIs status by below code (I am not sure if this is the right approach)

    static bool IsAddressAvailable(string address)
            {
                try
                {
                    System.Net.WebClient client = new WebClient();
                    string result = client.DownloadString(address);
                    client.DownloadData(address);  
                    
                    return true;
                }
                catch
                {
                    return false;
                }
            }

    Similarly I am looking for code to check if all my POST APIs are working.

    It's reasonable to assume if a GET request is successful then the Web API is up and running.  Why do you need to check the POST endpoints?  If you are looking for exceptions or unexpected results then look into standard logging and exception handling.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 12, 2020 1:20 PM
  • User-474980206 posted

    generally you want to know if the service is responding (periodic get ping), and if it is logging errors. 

    if the service connects to other services, add a ping that checks access to the other service. you might define a common set of health test apis, that all services implement. this with standardized logging of error should do what you want. call every api for a health test is not typical.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 12, 2020 3:16 PM