iosobjective-curlcode-organization

How to organize the API URL's in Objective-C


I am trying to organize all my API url's in a single file, what I am doing is I created a header file and added the following lines:

#define LOGIN_URL           @"http://192.168.100.100/api/login"
#define SIGNUP_URL          @"http://192.168.100.100/api/signup"
#define PRODUCTS_URL        @"http://192.168.100.100/api/products"
#define EMPLOYEE_URL        @"http://192.168.100.100/api/employee"
#define GET_PRODUCTS_URL    @"http://192.168.100.100/api/getproducts"
#define CLIENTS_URL         @"http://192.168.100.100/api/clients"

Here the base url is http://192.168.100.100/ which will keep on changing, I always have to find and replace the IP Address. Is there any better ways to organize API URL's?


Solution

  • Hey you may organise all your API Url's by using the following code

    #define SITE_URL(url) @"http://192.168.100.100/api" url
    
    #define LOGIN_URL           SITE_URL("/login")
    #define SIGNUP_URL          SITE_URL("/signup")
    
    #define PRODUCTS_URL        SITE_URL("/products")
    #define EMPLOYEE_URL        SITE_URL("/employee")
    #define GET_PRODUCTS_URL    SITE_URL("/getproducts")
    #define CLIENTS_URL         SITE_URL("/clients")