简体   繁体   中英

Data From REST API In Azure

I have implemented REST API calls using a standalone c# console application. The API returns JSON which i'm deserializing and then storing it in the database. Now i want to implement the entire logic in Azure platform so that it can invoked by passing start date and an end date and store location (it should run for three location) Below is the code:

static void Main()
    {


        MakeInventoryRequest();

    }

    static async void MakeInventoryRequest()
    {
        using (var client = new HttpClient())
        {
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "5051fx6yyy124hhfyuscf34f57ce9");


            // Request parameters

            queryString["query.locationNumbers"] = "4638";
            queryString["availableFromDate"] = "2019-01-01";
            queryString["availableToDate"] = "2019-03-07";


            var uri = "https://api-test.location.cloud/api/v1/inventory?" + queryString;

            using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
            using (var response = await client.SendAsync(request))
            {

                var stream = await response.Content.ReadAsStreamAsync();

                if (response.IsSuccessStatusCode == true)
                {
                    List<Inventory> l1 = DeserializeJsonFromStream<List<Inventory>>(stream);

                    InsertInventoryRecords(l1);
                }


                if (response.IsSuccessStatusCode == false)
                {
                    throw new Exception("Error Response Code: " + response.StatusCode.ToString() + "Content is: " + response.Content.ReadAsStringAsync().Result.ToString());
                }
            }
        }
    }

Please suggest the best possible design using Azure components

With the information in hand I think you have multiple options , you need to find out which works for you the best . You can use Cloud service to host the console app ( you will have to change it to worker role , Visual studio will help you to convert that ) . I am not sure about the load which you are expecting but you can always increase and decrease the instance and these can be deployed to different geographies .

I see that you are persisting the data , if you want to do that you can use many of the SQL offerings . For invoking the REST API you can also azure functions and ADF.

Please feel free to comment if you want any more details on the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM