I have a two sets of Urls one for PreProd and one for Prod. Each Url has several API nodes. Instead of hard coding these API nodes, I maintain them in an enum
Something like this:
//Prod private enum Prod { precheckorder, submitresubmit, creditInquiry, createupdateorder, confirmorder, getorderstatus, cancelorder, } /// <summary> /// Gets the relative URL. /// </summary> /// <param name="u">The u.</param> /// <returns></returns> /// <exception cref="Exception"></exception> private static string GetRelativeUrl(Prod u) { switch (u) { case Prod.precheckorder: return "https://contesa.tex.com/api/precheckorder"; case Prod.submitresubmit: return "https://contesa.tex.com/api/submitresubmit"; case Prod.creditInquiry: return "https://contesa.tex.com/api/creditinquiry"; case Prod.createupdateorder: return "https://contesa.tex.com/api/createupdateorder"; case Prod.confirmorder: return "https://contesa.tex.com/api/confirmorder"; case Prod.getorderstatus: return "https://contesa.tex.com/api/getorderstatus"; case Prod.cancelorder: return "https://contesa.tex.com/api/cancelorder"; default: // Handle bad URL, possibly throw throw new Exception(); } } We use environment variables to store the Environment name and thats what dictates which API set to use.
Ideally, I would like to have a single method, I pass in my environment and api name and it will return the API Url.
Something like
GettexApiUrlBasedOnEnvironment("Dev", "precheckorder"); and response will be
"https://contoso.tex.com/api/precheckorder" Any ideas/suggestions will be much appreciated. TIA