Search code examples
androidhttprequestandroid-volley

How/Where to store HTTP-Request URLs in Android?


I am not sure how/where I should store my Http-Request URLs and how to organize them.

I am developing a server and a client for Android. On the client I am using Volley for the network communication which so far seems like a very useful tool. The only thing I just don't know is the thing with all those Http-Request URLs.

Are there any best practices out there? Do I keep them all in a central class that provides all strings as a static field or do I store them as private field where I need them or is there another tool I can use for such things?


Solution

  • I have seen people generally doing the following things

    1. Keeping URLs in a holder class with static fields

    2. Keeping URLs in a resource XML file. This works exactly the same way as your strings.xml, but it is in a separate file. This comes in handy when using different server URLs in different app flavours

    3. Keeping only the base server URL and then appending query params to it in separate files... request methods.

    I use number two with conjunction with number three (keeping base URL in XML file and then appending stuff to the method)