protected void ForVerbAsync(RequestVerb verb, RouteSpecification route, IEnumerable <RouteHandlerAsync> handler) { if (verb == RequestVerb.Options || verb == RequestVerb.Head) { throw new ArgumentException(String.Format("Cannot register specific handlers for verb \"{0}\"", verb), "verb"); } _routes.Add(CreateRouteEntry(new RouteMatcher(verb, route), handler)); }
public RouteMatcher(RequestVerb verb, RouteSpecification route) { if (route == null) { throw new ArgumentNullException("route"); } this.Verb = verb; _routeString = SanatizeRoute(route.ResourceRoute); _resourceRegex = new Regex(BuildRouteRegex(_routeString), RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled); _paramMatches = route.UrlParameters; _hasUrlParameters = _paramMatches != null && _paramMatches.Length > 0; this.SortOrder = (_routeString.Split('/').Length + 1) + (_hasUrlParameters ? _paramMatches.Length * 3 : 0); }
protected void Delete(RouteSpecification route, params RouteHandler[] handler) { this.ForVerb(RequestVerb.Delete, route, handler); }
protected void PostAsync(RouteSpecification route, params RouteHandlerAsync[] handler) { this.ForVerbAsync(RequestVerb.Post, route, handler); }
protected void ForVerb(RequestVerb verb, RouteSpecification route, IEnumerable <RouteHandler> handlers) { var asyncHandlers = handlers.Select(h => new RouteHandlerAsync((r, d) => Task.FromResult <TResponse>(h(r, d)))); _routes.Add(CreateRouteEntry(new RouteMatcher(verb, route), asyncHandlers)); }
protected void Patch(RouteSpecification route, params RouteHandler[] handler) { this.ForVerb(RequestVerb.Patch, route, handler); }