1

Network call are made like this

@GET("/api/video/{slug}/show")
    void getVideoData(@Path("slug") String slug,Callback<VideoContainerGSON>cb);

Now I need to add wariable path before "/api" e.g:

/en/api/video/{slug}/show

Or

/sp/video/{slug}/show

That parameter is global wide, so without setting alteration all network call will use same language path.
Question: Is there a way to alter it without method signature or I must change method signature to

@GET("/{lang}/api/video/{slug}/show")
        void getVideoData(@Path("lang") String lang, @Path("slug") String slug,Callback<VideoContainerGSON>cb);
Yarh
  • 4,459
  • 5
  • 45
  • 95

1 Answers1

3

You can use string xmls to resolve your issue. You can put your api root in string.xml and override it in other xmls for example:

  • in values/string.xml

    <string name="api_root">http://yourapiroot.com/en</string>

  • in values-es/string.xml

    <string name="api_root">http://yourapiroot.com/sp</string>

and when you create your adapter set api root from resources as is shown in the code below:

new RestAdapter.Builder()
.setEndpoint(context.getString(R.string.api_root))
.build()

if you do not want to make the rest api from device language you can set params which defines language in api root in method where you build RestAdapter

And after that you start your paths from /api/... For example:

   @GET("/api/video/{slug}/show")
    void getVideoData(@Path("slug") String slug,Callback<VideoContainerGSON>cb);
Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45