예제 #1
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            long min = long.Parse(req.GetQueryNameValuePairs()
                                  .FirstOrDefault(q => string.Compare(q.Key, "Min", true) == 0)
                                  .Value);
            long max = long.Parse(req.GetQueryNameValuePairs()
                                  .FirstOrDefault(q => string.Compare(q.Key, "Max", true) == 0)
                                  .Value);

            var primes = PrimeCalc.GetPrimesAsJson(min, max);


            return(req.CreateResponse(HttpStatusCode.OK, primes));
        }
예제 #2
0
        // GET api/<controller>/5
        public async Task <string> Get(long min, long max, bool useFunc)
        {
            string primes;

            if (useFunc)
            {
                var apiKey  = AppSecrets.Secrets[FunctionKeyHeader];
                var baseUrl = ConfigurationManager.AppSettings["PrimeFunctionUrl"];
                var headers = new NameValueCollection();
                headers.Add(FunctionKeyHeader, apiKey);
                primes = await PrimeHttpHelper.GetJsonAsync(baseUrl, min, max, headers);
            }
            else
            {
                primes = PrimeCalc.GetPrimesAsJson(min, max);
            }

            return(primes);
        }