cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
abhrai
Level: Powered On

Check Web Service or Server is up and running or not using PowerApps

I have one of the requirements in my project to create a dashboard to let the users know whether a particular web service is up and running or not. Also, whether a particular server is up and running or not. How I can achieve this set of Dashboard functionality in PowerApps. Please suggest.

 

~abhrai

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Check Web Service or Server is up and running or not using PowerApps

PowerApps by itself doesn't have a way to check an arbitrary web service, as all communication is done via connectors (data sources). You can, however, create a custom connector that can do this.

To test this I create an Azure Function with the code below:

using System.Net;
using System.Net.Http;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string url = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "url", true) == 0)
        .Value;

    if (url == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();
        url = data?.url;
    }

    if (url == null) {
        return req.CreateResponse(HttpStatusCode.BadRequest, "Please inform the URL to test");
    }

    using (HttpClient c = new HttpClient()) {
        try {
            var resp = await c.GetAsync(url);
            log.Info($"Url: {url}, Status: {resp.StatusCode}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = (int)resp.StatusCode, Url = url });
        } catch (Exception ex) {
            log.Info($"Exception: {ex.GetType().FullName} - {ex.Message}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = 0, Url = url });
        }
    }
}

public class Result {
    public string Url { get; set; }
    public int StatusCode { get; set; }
}

And then use a custom connector - for example, with the OpenAPI definition below:

{
  "swagger": "2.0",
  "info": {
    "title": "ForumThread235074",
    "description": "Connector for https://powerusers.microsoft.com/t5/General-Discussion/Check-Web-Service-or-Server-is-up-and-running-or-not-using/m-p/235074",
    "version": "1.0"
  },
  "host": "YOUR.HOSTNAME.GOES.HERE.net",
  "basePath": "/api/",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/ForumThread235074": {
      "post": {
        "responses": {
          "default": {
            "description": "default",
            "schema": {
              "type": "object",
              "properties": {
                "Url": {
                  "type": "string",
                  "description": "Url"
                },
                "StatusCode": {
                  "type": "integer",
                  "format": "int32",
                  "description": "StatusCode"
                }
              }
            }
          }
        },
        "summary": "GetStatus",
        "description": "GetStatus",
        "operationId": "GetStatus",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": false,
            "schema": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "description": "url"
                }
              }
            }
          }
        ]
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

With this custom connector you can then have an app that can use that connector to check a certain web server is running.

Hope this helps!

2 REPLIES 2
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Check Web Service or Server is up and running or not using PowerApps

PowerApps by itself doesn't have a way to check an arbitrary web service, as all communication is done via connectors (data sources). You can, however, create a custom connector that can do this.

To test this I create an Azure Function with the code below:

using System.Net;
using System.Net.Http;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string url = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "url", true) == 0)
        .Value;

    if (url == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();
        url = data?.url;
    }

    if (url == null) {
        return req.CreateResponse(HttpStatusCode.BadRequest, "Please inform the URL to test");
    }

    using (HttpClient c = new HttpClient()) {
        try {
            var resp = await c.GetAsync(url);
            log.Info($"Url: {url}, Status: {resp.StatusCode}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = (int)resp.StatusCode, Url = url });
        } catch (Exception ex) {
            log.Info($"Exception: {ex.GetType().FullName} - {ex.Message}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = 0, Url = url });
        }
    }
}

public class Result {
    public string Url { get; set; }
    public int StatusCode { get; set; }
}

And then use a custom connector - for example, with the OpenAPI definition below:

{
  "swagger": "2.0",
  "info": {
    "title": "ForumThread235074",
    "description": "Connector for https://powerusers.microsoft.com/t5/General-Discussion/Check-Web-Service-or-Server-is-up-and-running-or-not-using/m-p/235074",
    "version": "1.0"
  },
  "host": "YOUR.HOSTNAME.GOES.HERE.net",
  "basePath": "/api/",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/ForumThread235074": {
      "post": {
        "responses": {
          "default": {
            "description": "default",
            "schema": {
              "type": "object",
              "properties": {
                "Url": {
                  "type": "string",
                  "description": "Url"
                },
                "StatusCode": {
                  "type": "integer",
                  "format": "int32",
                  "description": "StatusCode"
                }
              }
            }
          }
        },
        "summary": "GetStatus",
        "description": "GetStatus",
        "operationId": "GetStatus",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": false,
            "schema": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "description": "url"
                }
              }
            }
          }
        ]
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

With this custom connector you can then have an app that can use that connector to check a certain web server is running.

Hope this helps!

abhrai
Level: Powered On

Re: Check Web Service or Server is up and running or not using PowerApps

Thank you very much Carlos. This was really helpful.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

SixthImage

Power Summit Australia 2019

August 20-23rd 2019

Users Online
Currently online: 109 members 3,460 guests
Please welcome our newest community members: