是否可以在没有方法参数的情况下操作改造 url? [英] Is it possible to manipulate retrofit url without method parameter?

查看:35
本文介绍了是否可以在没有方法参数的情况下操作改造 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网络电话是这样打的

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

现在我需要在/api"之前添加wariable路径,例如:

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

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

/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);

推荐答案

您可以使用字符串 xmls 来解决您的问题.您可以将 api 根放在 string.xml 中并在其他 xml 中覆盖它,例如:

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:

  • values/string.xml

http://yourapiroot.com/en

values-es/string.xml

http://yourapiroot.com/sp

当您从资源创建适配器时,请设置 api root,如下面的代码所示:

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()

如果您不想从设备语言制作其余 api,您可以在构建 RestAdapter

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

然后你从 /api/... 开始你的路径例如:

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);

这篇关于是否可以在没有方法参数的情况下操作改造 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆