public APIRouter(string routeBase) { if (routeBase == null) { throw new ArgumentException("routeBase"); } _routeBase = routeBase; _server = new APIServer(Router, new string[] { _routeBase + "/" }); }
public void SendGenericResponse(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("<HTML><BODY><h1>Generic Handler</h1><p>{0}</p><p></p>", DateTime.Now); int x = 0; foreach (var part in requestParts) { sb.AppendFormat("<div><code>[{0}] is {1}</code></div>", x++, part); } sb.Append("</BODY></HTML>"); APIServer.SetResponse(response, sb.ToString()); }
public void Router(HttpListenerRequest request, HttpListenerResponse response) { string[] matches; APIRoute route = RouteMatch(request, out matches); if (route == null) { APIServer.SetResponse(response, HttpStatusCode.NotFound, ""); } else { route.Handler(request, matches, response); } }