Skip to content

Verifying operation

Joel Christner edited this page Nov 18, 2020 · 5 revisions

Several options exist to verify that Watson Webserver is operational.

From Within Your Code

Use the Server.IsListening property.

Server s = new Server("127.0.0.1", 8080, false, DefaultRoute);
s.Start();
Console.WriteLine(s.IsListening);

Using Netstat

From Windows Command Prompt, Linux Terminal, or Mac OSX terminal, use one of the following. In this example, Watson was started on port 8080.

Windows
C:\>netstat -ano | findstr ":8080"
  TCP    127.0.0.1:8080         0.0.0.0:0              LISTENING       4

Linux/Mac
$ netstat -ano | grep ":8080"

Using a Pre-Defined Request Handler

It is often helpful to define a static route for a well-known URL such as /loopback that will always return status 200 in the event that the server is running. This is often needed in environments with front-end loadbalancers which will use such an API for a healthcheck.

Server s = new Server("127.0.0.1", 8080, false, DefaultRoute);
s.Start();

[StaticRoute(HttpMethod.GET, "/loopback")]
static async Task LoopbackRoute(HttpContext ctx)
{
  ctx.Response.StatusCode = 200;
  await ctx.Response.Send();
}

Then you can access the URL using the browser, cURL, Postman, or a variety of other tools.

C:\>curl -i http://127.0.0.1:8080/loopback
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/octet-stream
Server: Microsoft-HTTPAPI/2.0
Access-Control-Allow-Origin: *
Date: Sat, 03 Aug 2019 02:45:17 GMT