Example #1
0
        public ApiModule(
            Func <IHttpApiRequestContext, T> httpApiFactory,
            IEnumerable <ApiEndpoint> apiEndpoints)
        {
            foreach (var apiEndpoint in apiEndpoints)
            {
                RouteBuilder routeBuilder;

                switch (apiEndpoint.HttpApiMethod)
                {
                case HttpApiMethod.Get:
                    routeBuilder = Get;
                    break;

                case HttpApiMethod.Post:
                    routeBuilder = Post;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                routeBuilder[apiEndpoint.Path, true] = (parameters, t) =>
                {
                    var dynamicDictionary     = (DynamicDictionary)parameters;
                    var httpApiRequestContext = new HttpApiRequestContext(this.Request.Body, dynamicDictionary.ToDictionary());
                    return(apiEndpoint.Invoker(httpApiRequestContext, t, httpApiFactory(httpApiRequestContext)));
                };
            }
        }
Example #2
0
            public INancyModule GetModule(Type moduleType, NancyContext context)
            {
                Func <IHttpApiRequestContext, INancyModule> nancyModule;

                if (_nancyModules.TryGetValue(moduleType, out nancyModule))
                {
                    var apiContext = new HttpApiRequestContext(context?.Request?.Body, Enumerable.Empty <KeyValuePair <string, object> >());
                    return(nancyModule(apiContext));
                }

                throw new Exception($"Module with type '{moduleType}' not found");
            }
Example #3
0
            public IEnumerable <INancyModule> GetAllModules(NancyContext context)
            {
                var apiContext = new HttpApiRequestContext(context?.Request?.Body, Enumerable.Empty <KeyValuePair <string, object> >());

                return(_nancyModules.Values.Select(f => f(apiContext)));
            }