/// <summary> /// Return stores using the request /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <StoreSearchResponse> StoreSearchAsync(StoreSearchRequest request) { StoreSearchResponse storeSearchResponse = null; string payload = string.Format(STORE_SEARCH_PAYLOAD, request.SearchText, string.Empty); int tries = 3; bool failed = false; do { tries--; failed = false; try { IRestRequest restRequest = new RestRequest(STORES_GRAPHQL_ENDPOINT, Method.POST); restRequest.AddParameter("application/json", payload, ParameterType.RequestBody); restRequest.AddCookie("_", "_"); //a cookie is required by the request contract, //restsharp requires that this not be an empty string in order for the header be set IRestResponse <StoreSearchResponse> restResponse = await _client.ExecutePostTaskAsync <StoreSearchResponse>(restRequest); storeSearchResponse = restResponse.Data; } catch (JsonReaderException) { failed = true; } }while (tries > 0 && failed); return(storeSearchResponse); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "KrogerCompare/StoreSearch/")] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); KrogerClient client = Startup.KrogerClient; StoreSearchRequest storeSearchRequest = JsonConvert.DeserializeObject <StoreSearchRequest>(req.Content.ReadAsStringAsync().Result); StoreSearchResponse storeSearchResponse = await client.StoreSearchAsync(storeSearchRequest); return(req.CreateResponse(HttpStatusCode.OK, storeSearchResponse)); }