改造 - 具有相同 RestAdapter 的多个端点 [英] Retrofit - Multiple endpoints with same RestAdapter

查看:44
本文介绍了改造 - 具有相同 RestAdapter 的多个端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何创建一个可以在两个端点之间切换的 RestAdapter.目前在我的应用程序中,RestAdapter 是在 Application 类(单例)中创建的.我正在寻找一种方法来拥有不同的端点,而无需实际创建多个 RestAdapter.

I would like to know how to create a RestAdapter that can switch between two endpoints. Currently in my app, the RestAdapter is created in the Application class(singleton). I am looking for a way to have different endpoints without actually creating multiple RestAdapter.

推荐答案

Endpoint 为每个请求调用.如果你想打开一个算法,你可以实现你自己的(例如,做循环).除此之外,单个 RestAdapter 与 Endpoint 相关联,您无法在每个方法或任何方法的基础上控制它.- 杰克沃顿

Endpoint is called for every request. If you want to switch on an algorithm you can implement your own (e.g., to do round-robin). Other than that, a single RestAdapter is tied to an Endpoint, you cannot control it on a per-method basis or anything. - Jake Wharton

因此,我为应用中使用的不同端点创建了不同的 rest 适配器.

So I created different rest adapters for the different endpoints I use in my app.

这篇关于改造 - 具有相同 RestAdapter 的多个端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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