Is it practical to use multiple functions for the same RestSharp Request?

Is it practical to create multiple function with same RestSharp parameters but different return statements?

For example:

I'll get the IP Address

    public string getIP()
        {
            RestClient client = new RestClient("http://ip-api.com/json/?fields=9009");
            var request = new RestRequest(Method.GET);
            IRestResponse response = client.Execute(request);
            string source = (response.Content);
            dynamic data = JObject.Parse(source);
            string IPAddress = data.query;
            return IPAddress;
            
        }

Is it good to use another like getCity() then using

string City = data.city;
return City;

and so on?


Solution 1:

If each API URL is the same, it would be better to call the API only once and parse the data multiple times, once for each field.

If the URL changes (for instance, http://ip-api.com/json/?fields=9009 for IP, http://city-api.com/json/?fields=9009 for city, etc.), then you would write multiple functions.

You should be able to return multiple values using output parameters: https://www.c-sharpcorner.com/UploadFile/9b86d4/how-to-return-multiple-values-from-a-function-in-C-Sharp/