public StartupApi(IDocumentDBRepository <Config> configRepo,
                   ISampleDataApi sampleDataApi,
                   IDocumentDBRepository <Metadata> metadataRepo)
 {
     _configRepo    = configRepo;
     _sampleDataApi = sampleDataApi;
     _metadataRepo  = metadataRepo;
 }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log,
                                                           [Inject(typeof(ISampleDataApi))] ISampleDataApi _sampleApi)
        {
            var httpMethods = new Dictionary <string, Func <HttpRequestMessage, TraceWriter, Task <HttpResponseMessage> > >
            {
                { "POST", async(r, l) => await _sampleApi.Post(r, l) }
            };

            var response = httpMethods.ContainsKey(req.Method.Method) ? await httpMethods[req.Method.Method](req, log)
                : req.CreateResponse(req.Method.Method == "OPTIONS" ? HttpStatusCode.OK : HttpStatusCode.NotFound);

            AddCORSHeader(req, response, $"POST, OPTIONS");

            return(req.CreateResponse(HttpStatusCode.Created));
        }