Where should I store the base url string in order to be able to make REST requests using a variable, representing this string, not hard-coding it every time I’m performing a request?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve found that it helps to create a separate header (.h) file, which defines the base URL as well as the extensions that I use for all calls. For example:
Then, in your appname_Prefix.pch file, import your new header file, so you don’t have to manually import it everywhere. The Prefix file is automatically appended to the beginning of each header file.
This has helped me immensely, and makes it so much easier to switch your app from sending requests to a dev API and a production API, as you only then have to change the URL in one place.